STL iterators in gcc 3.2

Moore, Mathew L MooreML@BATTELLE.ORG
Fri Oct 25 08:43:00 GMT 2002

> 1.- Whereas I didn't need it before, now I have to use the "using
> namespace std" directive if I want to use cout, cin,... and all this
> stuff. Why the change?

This version of gcc (and g++) is more standards compliant, hence the new
necessity of std:: when using the iostreams and other standard library

> 2.- This is more serious. In my programs I use a lot of STL 
> vectors, and
> so, iterators too. When I had a method with a pointer 
> argument, I passed a
> random iterator to it. It worked fine with previous versions 
> of gcc, but
> not with 3.2. Is there any way to get it work or do I have to 
> come back to
> an older version?

>From what I've noticed, the old 2.95 implemented std::vector iterators as
just plain pointers (|std::vector<double>| used |double*|'s for iteration).
It looks like now the library is using class abstractions for its iterators.
This has many benefits, but it also means that some code, e.g.,

	void foo(double*);
	std::vector<double> myvect;

will no longer work, since |myvect.begin()| does not necessarily produce a

I have found in order to make your code independent of the iterator object,
you have to either use templates,

	template <typename OutputIterator>
	void foo(OutputIterator);

or you must specifically use the iterator type defined by your container,

	void foo(std::vector<double>::iterator);

I don't know if there is an easier conversion than either of these, but I
would be interested in hearing any other ideas.


More information about the Gcc-help mailing list