g++ 2.95.4 has a problem with templates?

B

BigMan

Why g++ 2.95.4 does no compile the code at the end of the message? I
think the code is perfectly standard since 2 other compilers did
compile it (Microsoft C++ compiler that ships with MS VS.NET & Comeau
online compiler). If the problem is with the gnu compiler (version
2.95.4), is there any workaround? If there is no workaround, what
version of g++ compiles this code?

class c
{
public:
c( ) { }

template< unsigned int t >
void f( ) const
{
}
};

template< unsigned int t2 >
void f2( c const& cc)
{
cc.f< t2 >( ); // Here I get "parse error before `('".
}

int main
(
)
{
c const cc;
f2< 2 >( cc );
return 0;
}
 
R

Rolf Magnus

BigMan said:
Why g++ 2.95.4 does no compile the code at the end of the message?

There is actually no such GCC version as 2.95.4. See
http://gcc.gnu.org/releases.html for a list of all GCC versions ever
released.
I think the code is perfectly standard since 2 other compilers did
compile it (Microsoft C++ compiler that ships with MS VS.NET & Comeau
online compiler). If the problem is with the gnu compiler (version
2.95.4), is there any workaround? If there is no workaround, what
version of g++ compiles this code?

class c
{
public:
c( ) { }

template< unsigned int t >
void f( ) const
{
}
};

template< unsigned int t2 >
void f2( c const& cc)
{
cc.f< t2 >( ); // Here I get "parse error before `('".

g++ 3.3.3 makes it a "syntax error before `)'".

try instead:

cc.template f< t2 >( );

This makes it compile on g++ 3.3.3.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,662
Latest member
sxarexu

Latest Threads

Top