P
paul.joseph.davis
Hi,
I've just had my first encounter with two-phase lookup and I'm
scratching my head a bit. The idea behind two phase look up is pretty
easy to understand, but I have a case that fails to compile although
it appears to me that it should.
template<typename TYPE>
void
foo( std::map< int, TYPE > pmap )
{
std::map< int, TYPE >::iterator iter ;
}
When compiled with g++ 4.0.2 gives the following error:
test.cc: In function 'void foo(std::map<int, TYPE, std::less<int>,
std::allocator<std:
air<const int, TYPE> > >)':
test.cc:31: error: expected `;' before 'iter'
test.cc: In function 'void foo(std::map<int, TYPE, std::less<int>,
std::allocator<std:
air<const int, TYPE> > >) [with TYPE = char]':
test.cc:42: instantiated from here
test.cc:31: error: dependent-name
'std::map<int,TYPE,std::less<int>,std::allocator<std:
air<const int,
TYPE> > >::iterator' is parsed as a non-type, but instantiation yields
a type
test.cc:31: note: say 'typename
std::map<int,TYPE,std::less<int>,std::allocator<std:
air<const int,
TYPE> > >::iterator' if a type is meant
Unless I'm mistaken, this should be a dependant name lookup, and thus
not be looked up until template instantiation.
According to this article:
http://www.codeproject.com/cpp/TwoPhaseLookup.asp?df=100&forumid=115417&exp=0&select=949325
It should be dependant because its type is dependant. Which makes a
great deal of sense.
Given all that, what's causing this 'parsed as non-type' error?
This is purely an academic question, but its something I can't figure
out.
Thanks,
Paul Davis
I've just had my first encounter with two-phase lookup and I'm
scratching my head a bit. The idea behind two phase look up is pretty
easy to understand, but I have a case that fails to compile although
it appears to me that it should.
template<typename TYPE>
void
foo( std::map< int, TYPE > pmap )
{
std::map< int, TYPE >::iterator iter ;
}
When compiled with g++ 4.0.2 gives the following error:
test.cc: In function 'void foo(std::map<int, TYPE, std::less<int>,
std::allocator<std:
test.cc:31: error: expected `;' before 'iter'
test.cc: In function 'void foo(std::map<int, TYPE, std::less<int>,
std::allocator<std:
test.cc:42: instantiated from here
test.cc:31: error: dependent-name
'std::map<int,TYPE,std::less<int>,std::allocator<std:
TYPE> > >::iterator' is parsed as a non-type, but instantiation yields
a type
test.cc:31: note: say 'typename
std::map<int,TYPE,std::less<int>,std::allocator<std:
TYPE> > >::iterator' if a type is meant
Unless I'm mistaken, this should be a dependant name lookup, and thus
not be looked up until template instantiation.
According to this article:
http://www.codeproject.com/cpp/TwoPhaseLookup.asp?df=100&forumid=115417&exp=0&select=949325
It should be dependant because its type is dependant. Which makes a
great deal of sense.
Given all that, what's causing this 'parsed as non-type' error?
This is purely an academic question, but its something I can't figure
out.
Thanks,
Paul Davis