calling resize on std vector of pointers crashed
Posted
by
user11869
on Stack Overflow
See other posts from Stack Overflow
or by user11869
Published on 2014-05-27T21:20:59Z
Indexed on
2014/05/27
21:24 UTC
Read the original article
Hit count: 161
The problem can be reproduced using VS 2013 Express. It crashed when internal vector implementation tried to deallocate the original vector.
However, the problem can solved by using 'new' instead of 'malloc'.
Anyone can shed some light on this?
struct UndirectedGraphNode {
int label;
vector<UndirectedGraphNode *> neighbors;
UndirectedGraphNode(int x) : label(x) {};
};
int main(int argc, char** argv)
{
UndirectedGraphNode* node1 = (UndirectedGraphNode*)malloc(sizeof(UndirectedGraphNode));
node1->label = 0;
node1->neighbors.resize(2);
return 0;
}
© Stack Overflow or respective owner