I would like to use pointer to a vector of the data structure in one of my function.
1 2 3 4 5 6 7
void myVolSurf::readVolSurfData(string volSurfFile, myGlobSet * set, volSurfDef * def, vector<volSurfData> * vol)
// some code that loads value for vol_aux from txt file - works fine
(*vol).push_back(vol_aux); // HERE I get a programm execution break
The code is compiled without problems. However when I run it, some embeded vector code is generated and program breaks on
Well, it certainly would fail if you hadn't allocated any memory for the vector.
Are you also allocating space for whatever the set argument is pointing to? Do you use that pointer at all in readVolSurfData? Remember that, just because you declare a pointer, C++ doesn't magically allocate memory for the object being pointed to. You still have to create the actual object, one way or another.
(Edited because I didn't read your code properly the first time)
set is a function parameter and defined / initialized elsewhere. However def is treated in a similar manner without any problems. Anyway, the problem is definitely with a declaration / initialization as pointed out. As suggested by naraku9333, replacing
solved the problem without touching function readVolSurfData(). So, the problem seems to be solved (I will check once more tomorrow when back at work). However, I still wonder how it should have been using pointer. How should have I allocated a memory when I do not know the object size at its initialization?