I have a vector of floats, defined by:
std::vector<float>* MyVec;
and I was filling this inside a for loop later with:
MyVec->push_back(somevalue)
and I was getting a seg fault. In order to try and find out what was going on I commented out the push_back line and I still saw a seg fault, and when it seg faulted the size of MyVec was 490618047.
Is there perhaps something I have forgotten to do with this vector, and how is it getting filled by such a huge number without any entries being entered into the vector?
Thanks in advance.
You’ve not allocated memory:
Because
MyVecis a pointer tostd::vector<float>, you’ve to do the above, before usingMyVec.Also, don’t forget to deallocate the memory, once you’re done with
MyVec:Apart from that, I think, you don’t need a pointer to begin with; if so, then you should do the following instead of declaring a pointer:
And use it as: