Hello,
I have been struggling with a memory corruption/crash that causes the message in the subject and humbly ask for your help.
I narrowed down the code to just a few lines hopefully it will be easy to see what is that I'm doing wrong.
Here is the main program
And here is the header that defines the classes and the implementation:Code:#include "example.h" #include <vector> int main() { std::vector<exampleClass> objs; exampleClass test; objs.push_back(test); return 0; }
It seems that the crash occurs in the dst of the class Curve. Also, I noticed that it is called when the object "test" is pushed onto the vector.Code:class Curve { private: double *m_x; public: Curve(int n, double *x) { m_x = new double[n]; } ~Curve() { delete [] m_x; } }; /////////////////////////////////// class exampleClassComp { private: double val; Curve cv; public: exampleClassComp() : cv(0,0) { } friend class exampleClass; }; ////////////////////////////// class exampleClass { private: int id; exampleClassComp obj; public: exampleClass(void); }; /////////////////////////////// exampleClass::exampleClass(void) { id = 0; obj.val = 0.0; }
If anyone can offer some insight it would be much appreciated!
Thanks!



LinkBack URL
About LinkBacks



