On Apr 18, 4:19 pm, john.wilkinso...@[EMAIL PROTECTED]
wrote:
> The following code gives an "expected primary-expression before '>'"
> error when compiled with gcc, Dev-C++ version 4.9.9.2. There is no
> such error with MSVC 2005 or 2008. I would be grateful to know if it a
> gcc bug, or alternatively what is wrong with the code.
gcc conforms to the standard and VC++ is behaving smarter than what
the standard requires.
> template< typename G >
> struct Test
> {
> template< typename T > T f() const;
>
> };
>
> template< typename G, typename T >
> void g()
> {
> Test< G > t;
>
> t.f< T >(); // error re****ted for this line
> }
Above, f depends on a template parameter. It can be a member variable,
an enum value, a member function, etc. of Test<G>. Unless told, the
compiler cannot know that f is a template itself.
So it parses the < character as "less than" and gets confused later
on.
You must tell the compiler that f is a template so that it parses < as
the opening bracket of a template parameter list. Sorry for the busy
syntax: :)
t.template f< T >();
Ali
--
[ See http://www.gotw.ca/resources/clcm.htm
for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


|