473,387 Members | 3,787 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Compiler error instantiating iterator for vector of pointers

Hello,

I have a vector of pointers to a class, like so:

vector<Node*> m_parents;

I'm having trouble creating an iterator to go through the elements in
this vector. Here is my syntax:

vector<Node*>::iterator iter = m_parents.begin();

And here is the error I'm getting:

/usr/include/gcc/darwin/4.0/c++/bits/stl_iterator.h: In constructor
`__gnu_cxx::__normal_iterator<_Iterator,
_Container>::__normal_iterator(const
__gnu_cxx::__normal_iterator<_Iter, _Container>&) [with _Iter =
sbn::Node* const*, _Iterator = sbn::Node**, _Container =
std::vector<sbn::Node*, std::allocator<sbn::Node*> >]':
src/node.cpp:86: instantiated from here
/usr/include/gcc/darwin/4.0/c++/bits/stl_iterator.h:609: error: invalid
conversion from 'sbn::Node* const* const' to 'sbn::Node**'

Any ideas?

Thanks for all the help you guys have been giving me.

Carl

Nov 3 '05 #1
5 2923
cayblood wrote:
Hello,

I have a vector of pointers to a class, like so:

vector<Node*> m_parents;

I'm having trouble creating an iterator to go through the elements in
this vector. Here is my syntax:

vector<Node*>::iterator iter = m_parents.begin();

And here is the error I'm getting:

/usr/include/gcc/darwin/4.0/c++/bits/stl_iterator.h: In constructor
`__gnu_cxx::__normal_iterator<_Iterator,
_Container>::__normal_iterator(const
__gnu_cxx::__normal_iterator<_Iter, _Container>&) [with _Iter =
sbn::Node* const*, _Iterator = sbn::Node**, _Container =
std::vector<sbn::Node*, std::allocator<sbn::Node*> >]':
src/node.cpp:86: instantiated from here
/usr/include/gcc/darwin/4.0/c++/bits/stl_iterator.h:609: error: invalid
conversion from 'sbn::Node* const* const' to 'sbn::Node**'

Any ideas?

Thanks for all the help you guys have been giving me.

Carl


I would guess that you are calling this from within a const method.
Therefore you must use a const_iterator.

vector<Node*>::const_iterator iter = m_parents.begin();

If that's not it then quote a bit more of the code. Preferably enough so
that someone reading your post can actually compile the code and
reproduce the error.

john
Nov 3 '05 #2
I figured it out. Don't know why, but the method I'm calling this in
is a const method. It doesn't like the call to m_parents.begin(). I
thought it wasn't changing anything in the vector state, but apparently
it is.

Thanks,
Carl

Nov 3 '05 #3
cayblood wrote:
I figured it out. Don't know why, but the method I'm calling this in
is a const method. It doesn't like the call to m_parents.begin(). I
thought it wasn't changing anything in the vector state, but apparently
it is.

Thanks,
Carl


Because you are calling in a const method, the version of begin that you
are calling returns a const_iterator. It is not allowed to assign a
const_iterator to an iterator for obvious reasons.

john
Nov 3 '05 #4
I figured it out. Don't know why, but the method I'm calling this in
is a const method. It doesn't like the call to m_parents.begin(). I
thought it wasn't changing anything in the vector state, but apparently
it is.

Thanks,
Carl

Nov 3 '05 #5
I figured it out. Don't know why, but the method I'm calling this in
is a const method. It doesn't like the call to m_parents.begin(). I
thought it wasn't changing anything in the vector state, but apparently
it is.

Thanks,
Carl

Nov 3 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: amit kumar | last post by:
I am calling a function which returns pointer to a map. The declaration of the map is map<int,vectxyz*>. vectxyz is a vector containing pointer to a class xyz. For map<int,vectxyz*>* p1 In the...
29
by: Hagen | last post by:
Hello, in a recent thread "speed of vector vs array" I read about the problem of the slow acces by addressing vector elements by indexing, unfortunately I see no workaround in my case. My...
4
by: steflhermitte | last post by:
Dear cpp-ians, I am working with a structure struct segment { .... vector <meta_segment>::iterator it_Z; .... };
0
by: A Taylor | last post by:
Hello, I am getting the following error using .NET 2003 and I wonder if anyone can help me understand what is going on. godcDoc.cpp(228) : warning C4267: '=' : conversion from 'size_t' to...
1
by: mn04 | last post by:
I am getting the following error message during compilation of my C++ program on XP laptop using .NET libraries: ossxerces_utils.cxx...
7
by: Chameleon | last post by:
This code below compiles fine with VS.2005 but with gcc 3.4.2 not. ------------------ template<class T> static void Wastage1D::clever_erase(vector<T> &v, vector<typename vector<T>::iterator>...
18
by: silversurfer | last post by:
Ok, this should be fairly easy for most of you (at least I hope so), but not for me: Let us say we have got the following elements: std::vector<Entry> models; //Entry is a struct...
5
by: JoeC | last post by:
I am trying to make an iterator work with pointers. I wrote this code and it works but with an upgrade to my program vector is now unit* instead of unit type. void kill(std::vector<unit>& u){...
7
by: Ralf Goertz | last post by:
Hi, the following templated code doesn't compile. It gives the error: template_it.cc:17: error: type 'std::vector<Derived1<T>*, std::allocator<Derived1<T>*' is not derived from type...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.