c++內存泄露

#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;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章