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::__n ormal_iterator< _Iterator,
_Container>::__ normal_iterator (const
__gnu_cxx::__no rmal_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 5 2938
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::__n ormal_iterator< _Iterator, _Container>::__ normal_iterator (const __gnu_cxx::__no rmal_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
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
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
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 called function, I am using p1->find(1) which is returning a
valid iterator and not going to the end. I am returning p1 from the
called function.
But in the calling function, find(1) is going to the end, i.e unable
to find the key 1, which was...
|
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 case:
class A
{
|
by: steflhermitte |
last post by:
Dear cpp-ians,
I am working with a structure
struct segment
{
....
vector <meta_segment>::iterator it_Z;
....
};
|
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
'int', possible loss of data
C:\Program Files\Microsoft Visual Studio .NET
2003\Vc7\include\vector(621) : error C2440: 'initializing' : cannot
|
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
C:\narayan\axcelis\Lib\ossxerces_utils\src\OssDataFileTemplate.cxx(122) : error
C2582: 'operator =' function is unavailable in 'std::basic_ofstream<_Elem,_Trait
s>'
with
C:\narayan\axcelis\Lib\ossxerces_utils\src\OssDataFileTemplate.cxx(304) : error
C2440: 'return' : cannot convert from...
| |
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> &its, vector<T> &vo)
{ ........ }
------------------
I run gcc like this:
gcc -c wastage1d.cpp
|
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
std::vector<Entry>::iterator modelIterator;
In a method, I am currently writing, I need to get a pointer to an
entry in the vector.. I thought of the following:
|
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){
std::vector<unit>::iterator itr = u.begin();
while(itr != u.end()){
if (itr->marked()){
itr = u.erase(itr);
}else {++itr;}
|
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 'Derived2<T>'
template_it.cc:17: error: expected ';' before 'vi'
However, the same code compiles fine when I don't use any templates.
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |