In article
<6aceaefc-b74b-4632-b373-0d5794ae04d6@[EMAIL PROTECTED]
>,
john.wilkinson43@[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.
>
> 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
> }
You need
t.template f< T >();
The type of 't' depends on the template parameter 'G'. There is no
guarantee that in every specialisation of the template 'Test' the member
'f' will be a template. If the compiler is not told explicitly that 'f'
is in fact a template, it should assume that it is _not_, and parse '<'
as less-than rather than opening a template parameter.
Best wishes,
Matthew Collett
--
http://homepages.ihug.co.nz/~m_collett
[ See http://www.gotw.ca/resources/clcm.htm
for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]


|