#include <iostream>
using namespace std;
class SomeObject
{
public:
void SetValue(int value)
{
this->value = value;
}
int GetValue()const
{
return this->value;
}
private:
int value;
};
int main()
{
SomeObject* so = new SomeObject;
if (NULL == so)
{
return 1;
}
so->SetValue(1000);
SomeObject *cp = so;
cout << cp->GetValue() << endl;//1)
delete so;
so = NULL;
cout << cp->GetValue() << endl;//2)
return 0;
}
2)处出错,因为删除掉了,虽然本意是删除某个数值,但是他们是共用一个地址的,在删除的时候也对原来占用的指针删除掉了.低级错误,不可忽视.