470,821 Members | 2,084 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,821 developers. It's quick & easy.

gcc cant support this ??

the following code:

template <class T>
class test{
typedef T::XXX x;
};

int main(){
return 0;
}
Cant be compiled by mingw (but can by borland c++ 5.5) .
Cant gcc support this ?


May 21 '06 #1
7 1604
William.Zhang wrote:
template <class T>
class test{
typedef T::XXX x;
};

int main(){
return 0;
} Cant be compiled by mingw (but can by borland c++ 5.5) .
Cant gcc support this ?


What error message do you get? What line does it point to?

I don't fully understand 'typename', but you can try that instead of
'class'...

--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!
May 21 '06 #2
William.Zhang wrote:
the following code:

template <class T>
class test{
typedef T::XXX x;
change to typedef typename T::XXX x;
};

int main(){
return 0;
}
Cant be compiled by mingw (but can by borland c++ 5.5) .
Cant gcc support this ?

In my opinion, it shouldn't be compiling an unused template...

--
Ian Collins.
May 21 '06 #3
William.Zhang wrote:
the following code:

template <class T>
class test{
typedef T::XXX x;
This should read:

typedef typename T::XXX x;

The compiler is not entitled to assume that T::XXX is a typename, so it has
to be told.
};

int main(){
return 0;
}
Cant be compiled by mingw (but can by borland c++ 5.5) .
Cant gcc support this ?


Your code is in error, g++ is correct.
Best

Kai-Uwe Bux
May 21 '06 #4

Ian Collins wrote:
William.Zhang wrote:

Cant be compiled by mingw (but can by borland c++ 5.5) .
Cant gcc support this ?

In my opinion, it shouldn't be compiling an unused template...


Yeah, that's a pretty serious violation of the standard.

May 21 '06 #5
this is OK:
typedef typename T::XXX x;

gcc is strict to c++.

"Phlip" <ph******@yahoo.com> 写入消息新闻:JC*******************@newssvr21.news. prodigy.com...
William.Zhang wrote:
template <class T>
class test{
typedef T::XXX x;
};

int main(){
return 0;
}

Cant be compiled by mingw (but can by borland c++ 5.5) .
Cant gcc support this ?


What error message do you get? What line does it point to?

I don't fully understand 'typename', but you can try that instead of
'class'...

--
Phlip
http://c2.com/cgi/wiki?ZeekLand <-- NOT a blog!!!

May 22 '06 #6

Noah Roberts wrote:
Ian Collins wrote:
William.Zhang wrote:

Cant be compiled by mingw (but can by borland c++ 5.5) .
Cant gcc support this ?

In my opinion, it shouldn't be compiling an unused template...


Yeah, that's a pretty serious violation of the standard.


Instantiating it would be a violation. Compiling it is mandatory. This
is the reason
we talk about two-phase name lookup for templates, in both phases name
lookup
happens. 'typename' is needed here (as others have shown) because it
tells the
compiler in phase 1 (compilation) what the results of phase 2
(instantiation) will be.

HTH,
Michiel Salters

May 22 '06 #7
Mi*************@tomtom.com wrote:
Noah Roberts wrote:
Ian Collins wrote:
William.Zhang wrote:

Cant be compiled by mingw (but can by borland c++ 5.5) .
Cant gcc support this ?
In my opinion, it shouldn't be compiling an unused template...


Yeah, that's a pretty serious violation of the standard.

Instantiating it would be a violation. Compiling it is mandatory. This
is the reason
we talk about two-phase name lookup for templates, in both phases name
lookup
happens. 'typename' is needed here (as others have shown) because it
tells the
compiler in phase 1 (compilation) what the results of phase 2
(instantiation) will be.

Can you point me at the appropriate part of the standard? I've never
been 100% sure what the compiler should do with unused templates, beyond
checking they are well formed.

--
Ian Collins.
May 22 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Uwe Mayer | last post: by
1 post views Thread by andrewcw | last post: by
6 posts views Thread by erdem kemer | last post: by
3 posts views Thread by Michael Evanchik | last post: by
reply views Thread by Tony Lewis | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.