Dict* test = (Dict*)malloc(sizeof(Dict));
does not do what you think it does.
malloc
allocates a block of memory, but does not initialize it. So later on, when you call test->nodes.push_back
, you’re calling into uninitialized memory. Undefined behavior. In your case, it crashes.
The solution here is allocate test
with new
, which will initialize both test
and test->nodes
.
Dict* test = new Dict;
The even better solution is to ask why test
is dynamically allocated to begin with.
0
solved std::vector push_back results in access Violation