Get Time
Search | Watch Thread  |  My Post History  |  My Watches  |  User Settings
View: Flat (newest first)  | Threaded  | Tree
Previous Thread  |  Next Thread
C++ compiler bug? | Reply
Just wondering what version of gcc is being used. I had problems with code not compiling. Here is a simplified example:

template<class T> void test() {
T::some_sub_type x;

This is perfectly valid code I believe and works in VC++, borland etc. But in Topcoder I get the following compiler error:

XXX.C: In function `void test ()':
XXX.C:2: parse error before `;'

Re: C++ compiler bug? (response to post by pdennis) | Reply
We are currently using g++ 2.96 on linux.
Re: C++ compiler bug? (response to post by pdennis) | Reply
Sorry. Seems like maybe this is a problem with the other compilers since the Comeau compiler also gives an error. I found that:

template<typename T> void test() {
typename T::some_type x;

works as expected. I guess I will have to check up on what the standard actually says.

Even so, any plans to move to the latest version of gcc? I have heard that version 3.x has been out for a while now and has significant improvments over 2.x.
Re: C++ compiler bug? (response to post by pdennis) | Reply
This is not correct code. It is not ANSI compliant. Just because VC++ compiles it doesn't make it correct. In fact that would be more suspect.

You must use the typename keyword when referencing a type member of a template. The keyword is not optional. So in your case the correct thing is:

typename T::some_sub_type x;

The reason this is necessary is because there are times that if you do not provide the typename keyword, there is an ambiguity. For instance:

template<class T> void foo () {
T::A() // construct temporary object of type T::A
// or call member function T::A()?