Re: Compiler error using 4.5.2 with function template

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Edward,
On Sat, Mar 05, 2011 at 11:17:52AM -0500, Edward Diener wrote:
> This very simple program:
>
> template<class T> struct ATemplate { };
> template<class T> void check(ATemplate<&T::SomeFuncTemplate<int> > *);
>
> int main()
>   {
>   return 0;
>   }
>
> produces a compiler error:
>
> "test_has_mem_fun_template.cpp:2:66: error: template argument 1 is invalid
>
>     "g++"  -ftemplate-depth-128 -O0 -fno-inline -Wall -pedantic -g  
> -Wno-variadic-macros   -I"..\..\.."  
> -I"C:\Programming\VersionControl\boost" -c -o  
> "..\..\..\bin.v2\libs\tti\test\test_has_mem_fun_template.test\gcc-mingw-4.5.2\debug\test_has_mem_fun_template.o" 
> "test_has_mem_fun_template.cpp""
>
> I suspect that I need to add the 'template' keyword to tell the compiler  
> that SomeFuncTemplate is a function template but all my attempts appear  
> to fail.
>
> Is this a compiler bug or do I need to do something else above ?
The compiler is right.
As soon as you assume that an element of an unknown class is a
class-type, you have to tell the compiler by adding a typename. E.g.
expressions of the form (T being a template parameter):
	A<T>::B
	T::B
are NO typenamesâ What you need, is
	typename A<T>::B
	typename T::B
such that the compiler understands that "B" will be a type.

I don't understand what you want exactly. However, the following works:
if "T::SomeType" is a type which does not depend on a template
parameter:
template<class T> void check(ATemplate<typename T::SomeType > *);

if "T::SomeFuncTemplate" is a type which depends on a given parameter
(in your example: int), you have to add an additional "template":

template<class T> void check(ATemplate<typename T::template SomeFuncTemplate<int> > *);

if that doesn't solve your problem, could you give as also an axample
for the class "T" -- so that we can see the precise definition of
::SomeFuncTemplate<int> ?

HTH,

Axel



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux