Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
代码是
Vect::~Vect() /* PRE: None POST: free pVect */ { cout << "(__|| - DELETE (unlock the memory for): " << (*this) << endl; // Put code below .... }
基本上,我需要它来正确释放 pVect,以便我的其他功能可以工作。
还有一个带有这个 double* pVect 的 .h 文件;
如果您提供了一个完整但最少可生产的示例,那就太好了。让我们试试这个:
class Vect { public: ~ Vect(); private: double *pVect = nullptr; }; Vect::~ Vect() { delete [] pVect; }
确保保持pVect等于 a nullptr,除非它包含有效地址。这意味着你绝对应该像我一样给它一个默认值。
pVect
nullptr