#includeusing namespace std;class person {public:person() { cout << "无参构造的调用" << endl; }void show(){cout << "年龄为:"<<18 << endl; }~person(){cout << "析构函数的调用" << endl;}};void test(){person* p=new person;p->show();}int main(){test();system("pause");return 0;}

智能指针:托管new出来的对象的释放
#includeusing namespace std;class person {public:person() { cout << "无参构造的调用" << endl; }void show(){cout << "年龄为:"<<18 << endl; }~person(){cout << "析构函数的调用" << endl;}};class smartpoint {public:smartpoint(person* person){this->p = person;}person* operator->(){return this->p;}person& operator*(){return *(this->p);}~smartpoint(){if (p != NULL){delete p;p = NULL;}}private:person* p;};void test(){smartpoint sp(new person());sp->show();(*sp).show();}int main(){test();system("pause");return 0;}
