* gcc-3.4 requires 'typename' to use map in a template?
@ 2003-10-02 23:56 Dan Kegel
2003-10-03 0:39 ` Dan Kegel
0 siblings, 1 reply; 4+ messages in thread
From: Dan Kegel @ 2003-10-02 23:56 UTC (permalink / raw)
To: gcc
The following code is rejected by gcc-3.4-20031001, but accepted
by gcc-2.95 and gcc-3.2.3:
#include <map>
template <typename T>
class myclass {
typedef std::map<T, unsigned int> mymap;
public:
void mymethod() {
mymap::iterator myvar;
myvar = 0;
}
};
Command to reproduce:
$ /usr/local/gcc-3.4-20031001/bin/g++ foo2.cc
foo2.cc: In member function `void myclass<T>::mymethod()':
foo2.cc:8: error: expected `;'
foo2.cc:9: error: `myvar' undeclared (first use this function)
Using the typename keyword seems to be a workaround, as
gcc-3.4-20031001 accepts the following code without complaint:
#include <map>
template <typename T>
class myclass {
typedef std::map<T, unsigned int> mymap;
public:
void mymethod() {
typename mymap::iterator myvar;
myvar = 0;
}
};
So is gcc-3.4-20031001 right to require typename here, or is this a bug?
- Dan
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: gcc-3.4 requires 'typename' to use map in a template?
2003-10-02 23:56 gcc-3.4 requires 'typename' to use map in a template? Dan Kegel
@ 2003-10-03 0:39 ` Dan Kegel
2003-10-03 0:51 ` David Carlton
0 siblings, 1 reply; 4+ messages in thread
From: Dan Kegel @ 2003-10-03 0:39 UTC (permalink / raw)
To: Dan Kegel; +Cc: gcc
Dan Kegel wrote:
> #include <map>
>
> template <typename T>
> class myclass {
> typedef std::map<T, unsigned int> mymap;
> public:
> void mymethod() {
> typename mymap::iterator myvar;
> myvar = 0;
> }
> };
>
> So is gcc-3.4-20031001 right to require typename here, or is this a bug?
The local language lawyer says yep, gcc-3.4 could be right;
since mymap depends on T, it needs the 'typename'.
But shoot, you'd *think* a typedef would be enough of a clue!
Man, is this nonintuitive...
I guess I'll run out and buy that book _C++ Templates: The Complete Guide_
mentioned in the previous post,
http://gcc.gnu.org/ml/gcc/2003-10/msg00082.html
- Dan
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: gcc-3.4 requires 'typename' to use map in a template?
2003-10-03 0:39 ` Dan Kegel
@ 2003-10-03 0:51 ` David Carlton
2003-10-03 0:59 ` Dan Kegel
0 siblings, 1 reply; 4+ messages in thread
From: David Carlton @ 2003-10-03 0:51 UTC (permalink / raw)
To: Dan Kegel; +Cc: gcc
On Thu, 02 Oct 2003 17:29:40 -0700, Dan Kegel <dkegel@ixiacom.com> said:
> Dan Kegel wrote:
>> #include <map>
>> template <typename T>
>> class myclass {
>> typedef std::map<T, unsigned int> mymap;
>> public:
>> void mymethod() {
>> typename mymap::iterator myvar;
>> myvar = 0;
>> }
>> };
>> So is gcc-3.4-20031001 right to require typename here, or is this a
>> bug?
> The local language lawyer says yep, gcc-3.4 could be right;
> since mymap depends on T, it needs the 'typename'.
> But shoot, you'd *think* a typedef would be enough of a clue!
My understanding is that it's not that it needs help figuring out that
mymap is a type, it needs help figuring out that mymap::iterator is a
type. (Which it might or might not be for different values of T, if
you inserted some particularly perverse specializations of std::map.)
David Carlton
carlton@kealia.com
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: gcc-3.4 requires 'typename' to use map in a template?
2003-10-03 0:51 ` David Carlton
@ 2003-10-03 0:59 ` Dan Kegel
0 siblings, 0 replies; 4+ messages in thread
From: Dan Kegel @ 2003-10-03 0:59 UTC (permalink / raw)
To: David Carlton; +Cc: gcc
David Carlton wrote:
> My understanding is that it's not that it needs help figuring out that
> mymap is a type, it needs help figuring out that mymap::iterator is a
> type. (Which it might or might not be for different values of T, if
> you inserted some particularly perverse specializations of std::map.)
Ahh. It makes sense. Thanks!
- Dan
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2003-10-03 0:59 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-10-02 23:56 gcc-3.4 requires 'typename' to use map in a template? Dan Kegel
2003-10-03 0:39 ` Dan Kegel
2003-10-03 0:51 ` David Carlton
2003-10-03 0:59 ` Dan Kegel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).