template<class T> class A
{
void foo(void)
{
for(list<T*>::iterator i = m_List.begin(); i != m_List.end(); ++i)
(...)
}
list<T*> m_List;
};
The problem seems to be with the declaration of i. Is this a known bug in g++?
Compile Error in g++
The following code compiles fine in msvc++ but produces errors in g++, does anyone know of a workaround?
template<class T> class A{ void foo(void) { for(typename list<T*>::iterator i = m_List.begin(); i != m_List.end(); ++i) (...) } list<T*> m_List;};
May 04, 2005 05:14 AM
When you're implicitly creating a type from a template parameter eg: std::list::iterator you need to tell the compiler that it's a type using the typename keyword, otherwise it gets confused and throws an error. I've fallen foul of this a few times in GCC, MSVC always used to handle it fine.
Note that MSVC++ is just trying to being nice to you there -- the standard requires the typename. Some versions of G++ will give you an "implicit typename is deprecated" warning, however, and compile properly if it correctly guesses it's a type. Don't count on it for long though -- the support of implicit typenames wont be included in the next version, iirc.
May 06, 2005 03:40 PM
Quote: Original post by me22
Note that MSVC++ is just trying to being nice to you there....
That's the kind of "help" no sane person would like. Thanks MSVC for helping us write broken code.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement