Re: [Doxygen-users] warning at explicit instantiation of overloaded template class member function
Brought to you by:
dimitri
|
From: Dimitri v. H. <do...@gm...> - 2015-08-26 15:45:22
|
Hi Harald,
> On 26 Aug 2015, at 16:32 , Heese, Harald <har...@ph...> wrote:
>
> Hi Dimitri!
>
> Thanks for the quick answer.
>
> You are right, the provided code does not compile. The modified example now is
>
> //! a test class with overloaded template members
> class Bar
> {
> public:
> //! first overload of template member function
> template <typename T>
> T foo(T a, int b)
> { return a; }
>
> //! second overload of template member function
> template <typename T>
> T foo(T a, double c)
> { return a; }
> };
>
> //! force instantiation of first overload for type 'short'
> template short Bar::foo<short>(short, int);
>
> If you compile this using
> gcc -c bar.cpp
>
> the corresponding object file will contain exactly one symbol (which you can see using nm). This is exactly what is intended (to force the creation of a symbol for a specific template parameter).
>
> The syntax you suggested refers to a different concept, namely "template specialization". In that case, the statement
> template<> short Bar::foo<short>(short, int);
> is a function declaration, which would require a separate function definition in order to create a corresponding symbol. If I would compile the modified example with your suggestion, then the corresponding object file does not contain any symbols (which is not what is intended).
I see. A solution/workaround is to use \relates, i.e.:
//! \relates Bar
//! \brief force instantiation of first overload for type 'short'
template short Bar::foo<short>(short, int);
Regards,
Dimitri
|