Using STL iterator as class member variable [modified]
-
I'm trying to implement a "MFC CList look-alike" wrapper on top of the STL list using MS Visual C++ 2005 Express. The implementation of the iteration methods begin-next-prev-end requires a storage of the position in the class like this:
#include template< class TYPE> class CList { protected: std::list< TYPE >::iterator pos; ...
But it doesn't work... I get these compiler errors: warning C4346: 'std::list< TYPE >::iterator' : dependent name is not a type error C2146: syntax error : missing ';' before identifier 'pos' error C4430: missing type specifier - int assumed. Note: C++ does not support default-int I don't quite understand the errors. Using the same declaration (std::list< TYPE >::iterator p) in a member function, I don't get any errors at all from the compiler. Why am I not allowed to declare this iterator (pos) as a member in the class? Hope someone can help? -- modified at 11:45 Tuesday 5th June, 2007 -- modified at 11:46 Tuesday 5th June, 2007Anton112
-
I'm trying to implement a "MFC CList look-alike" wrapper on top of the STL list using MS Visual C++ 2005 Express. The implementation of the iteration methods begin-next-prev-end requires a storage of the position in the class like this:
#include template< class TYPE> class CList { protected: std::list< TYPE >::iterator pos; ...
But it doesn't work... I get these compiler errors: warning C4346: 'std::list< TYPE >::iterator' : dependent name is not a type error C2146: syntax error : missing ';' before identifier 'pos' error C4430: missing type specifier - int assumed. Note: C++ does not support default-int I don't quite understand the errors. Using the same declaration (std::list< TYPE >::iterator p) in a member function, I don't get any errors at all from the compiler. Why am I not allowed to declare this iterator (pos) as a member in the class? Hope someone can help? -- modified at 11:45 Tuesday 5th June, 2007 -- modified at 11:46 Tuesday 5th June, 2007Anton112
Interesting, as your code snippet compiles fine with VS6.
template<class T>
class CList
{
protected:
std::list<T>::iterator pos;
};I'd guess that it has to do with VS2005 being more C++ compliant. See here.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
Interesting, as your code snippet compiles fine with VS6.
template<class T>
class CList
{
protected:
std::list<T>::iterator pos;
};I'd guess that it has to do with VS2005 being more C++ compliant. See here.
"A good athlete is the result of a good and worthy opponent." - David Crow
"To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne
-
I'm trying to implement a "MFC CList look-alike" wrapper on top of the STL list using MS Visual C++ 2005 Express. The implementation of the iteration methods begin-next-prev-end requires a storage of the position in the class like this:
#include template< class TYPE> class CList { protected: std::list< TYPE >::iterator pos; ...
But it doesn't work... I get these compiler errors: warning C4346: 'std::list< TYPE >::iterator' : dependent name is not a type error C2146: syntax error : missing ';' before identifier 'pos' error C4430: missing type specifier - int assumed. Note: C++ does not support default-int I don't quite understand the errors. Using the same declaration (std::list< TYPE >::iterator p) in a member function, I don't get any errors at all from the compiler. Why am I not allowed to declare this iterator (pos) as a member in the class? Hope someone can help? -- modified at 11:45 Tuesday 5th June, 2007 -- modified at 11:46 Tuesday 5th June, 2007Anton112
-
iterator cannot be deduced as a type by the compiler. To make it (compiler) think so, put typename in front of its declaration;
template<class T>
class CList{
protected:
typename std::list<T>::iterator pos;
};-- ===== Arman