By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,654 Members | 936 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,654 IT Pros & Developers. It's quick & easy.

g++ 2.95.4 has a problem with templates?

P: n/a
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;
}

Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
BigMan wrote:
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.
}

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


Jul 23 '05 #2

P: n/a
Your solution works just fine. Thanks a lot!

Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.