mardi 5 janvier 2016

Crash because of function definition in header file

e2o.h

Class e2o { public: e2o(const TweakPtr &Sheetinfo); TweakPtr GetInfo(void ){ return m_sheetInfo}; // Line #1 TweakPtr GetInfo(void ){ return m_sheetInfo};

private: TweakPtr m_sheetInfo;

}

e2o.cpp

e2o::e2o(const TweakPtr &Sheetinfo):m_sheetInfo(Sheetinfo) { ... }

xyz.cpp

e2o *ptr = new e2o(sheetInfo);

ptr->GetInfo(); // Line#2 : Crash here

Now My application is crashing (at line #2) if i try to get the info by calling function getInfo() at Line #1. From Line#1 its internally calling the copy constructor of TweakPtr.

Now, one interesting part is i moved the definition of GetInfo() from e2o.h to e2o.cpp file. After this changes my function's working fine.

Any specific reason for that. My problem has been solved, but i don't know the exact reason.

Aucun commentaire:

Enregistrer un commentaire