Tuesday, 15 February 2011

c++ - How to add a value to a *vector? -



c++ - How to add a value to a *vector? -

in header file have vector defined pointer.

private: vector<filteredpoint_t> *filteredvalues;

in cpp file want add together instance of (struct) filterpoint_t vector. compiles.

filteredpoint_t fp; fp.filteredvalue = 3.4; fp.globalindex = 3; filteredvalues->push_back(fp);

however, when run it, stops after invocation of filteredvalues->push_back(fp). not prinf console outputs shown. no error message though on console.

what missing here?

some background information: need pass filteredvalues multiple threads. every thread can write variable. hence thought utilize pointer variable so.

you need allocate memory first ( may constructor ) or point valid vector<filteredpoint_t> address:

filteredvalues = new vector<filteredpoint_t>() ;

then can utilize push_back on it.

also, create sure de-allocate memory allocated using new in destructor

delete [] filteredvalues ;

c++

No comments:

Post a Comment