c++ - vector<float>* causing seg fault! -
i have vector of floats, defined by:
std::vector<float>* myvec;
and filling inside loop later with:
myvec->push_back(somevalue)
and getting seg fault. in order try , find out going on commented out push_back line , still saw seg fault, , when seg faulted size of myvec 490618047.
is there perhaps have forgotten vector, , how getting filled such huge number without entries being entered vector?
thanks in advance.
you've not allocated memory:
std::vector<float>* myvec = new std::vector<float>();
because myvec
pointer std::vector<float>
, you've above, before using myvec
.
also, don't forget deallocate memory, once you're done myvec
:
delete myvec;
apart that, i think, don't need pointer begin with; if so, should following instead of declaring pointer:
std::vector<float> myvec; //it not pointer.
and use as:
myvec.push_back(somefloatvalue);
Comments
Post a Comment