STF STF - 3 years ago 229
C++ Question

converting from iterator to the object c++

I have an iterator that going over a list, and I try to convert the iterator to the object.

std::list<XMLObjects>::const_iterator objectsIterator;
for (objectsIterator = frame->getObjectsList().begin(); objectsIterator != frame->getObjectsList().end(); ++objectsIterator)
{
XMLObjects object =(*objectsIterator);
}


but I get an error:


Unhandled exception at 0x00007FFA9A658384 in OR_Comparator.exe:
Microsoft C++ exception: std::bad_alloc at memory location
0x0000007C0196C490.


who can I convert it in a good way?

Answer Source

write

std::list<XMLObjects>::iterator objectsIterator;

instead of

std::list<XMLObjects>::const_iterator objectsIterator;

and then write in the for:

xmlObjects &gt=(*objectsIterator);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download