This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
RE: STL iterator problem
- From: "Martin York" <martin dot york at veritas dot com>
- To: <kini1982 at postmaster dot co dot uk>,<gcc-help at gcc dot gnu dot org>
- Date: Wed, 24 Nov 2004 09:02:29 -0600
- Subject: RE: STL iterator problem
Here is what I have found.
Hope this helps.
> for(B::iterator i = the_Container->Begin(); i != the_Container->end();
++i )
The problem is cause because B is a template class and g++ can not
guarantee that B::iterator is a type (could be a static member variable)
when it fist parses the function. g++ adheres strictly to the standard
which requires that in these situations you use the typename keyword to
disambigiufy the situation. Sorry can not quote chapter and verse on
what part of the standard.
PS. Also note that the method Begin() should probably be begin().
> for(typename B::iterator i = the_Container->begin(); i !=
the_Container->end(); ++i )
Martin
-----Original Message-----
From: gcc-help-owner@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org] On
Behalf Of Yogesh Kini
Sent: 24 November 2004 03:21
To: gcc-help@gcc.gnu.org
Subject: STL iterator problem
Hi,
Please take a look at the code snippet below.
The code compiles fine with Microsoft VC++ but gives a error with gcc(as
indicated below) I am trying to port the file from msvc to gcc. Can
anyone suggest me a work around.
Thanks
Yogesh
#include <stdio.h>
#include <list>
template <class B>
class parent
{
public:
B * m_Container;
void funone();
void CreateList()
{
m_Container = new B();
m_Container->push_front(1);
m_Container->push_front(2);
m_Container->push_front(3);
m_Container->push_front(4);
}
B * GetList()
{
return (m_Container);
}
};
template<class B>
void parent<B>::funone()
{
B * the_Container = GetList();
for(B::iterator i = the_Container->Begin(); i !=
the_Container->end(); ++i ) -> Error Here: Parse error before "="
token
{
printf("%d ",*i);
}
}
int main()
{
parent<std::list<int>> the_instance;
the_instance.CreateList();
the_instance.funone();
}
Error: parse error before "=" token
___________________________________________________
Have your own email and web address for life.
http://www.homemaster.net - Homemaster. Come Together. Online.