#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)處出錯,因為刪除掉了,雖然本意是刪除某個數值,但是他們是共用一個地址的,在刪除的時候也對原來占用的指針刪除掉了.低級錯誤,不可忽視.