c++内存泄露

来源:互联网 发布:播音腔怎么练 知乎 编辑:程序博客网 时间:2024/06/07 16:48
#include <iostream>using namespace std;class Simple {public:Simple() { mIntPtr = new int(); }~Simple() { delete mIntPtr; }void setIntPtr(int inInt) { *mIntPtr = inInt; }protected:int *mIntPtr;};void doSomething(Simple *&outSimplePtr){outSimplePtr = new Simple(); //BUG! Doesn`t delete the original.}int main(){Simple *simplePtr = new Simple();doSomething(simplePtr);delete simplePtr;return 0;}

0 0
原创粉丝点击