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

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -