Reputation: 4522
I am currently working on a simulator and encountered the following error during debug runtime: Expression: vector incompatible iterators
The code is as follows:
class Network {
private:
vector<Node*> nodes;
....
void parse_config(void);
....
};
And in the parse_config method I have a sequence which generates the error. This is it:
if(nodes.empty()) // add the first node to the network
{
Node current(regex_d[1]); // create current(first src) node
Node *acurrent = ¤t;
Node next_hop(regex_d[2]); // create the node we immediately send to
Node *anext_hop = &next_hop;
acurrent->add_next_hop(anext_hop);
acurrent->add_n_vchannels(regex_d[5]);
nodes.push_back(acurrent); // <== error
nodes.push_back(anext_hop); // <== here as well
}
Is there a workaround this? Any help/suggestion/reference will be very much appreciated.
Sebi
Upvotes: 1
Views: 893
Reputation: 1685
Your pointer is pointing to a stack object. While this is not evident in your code, it is very likely that you have some pointers in your nodes vector which have been reclaimed. In the above:
Node *acurrent = new Node(regex_d[1]);
would make at least the memory problems more accurate.
As for the issues you are encountering, perhaps the memory location was used for something else causing your pointer to point to a completely different object than a Node.
Upvotes: 1