我们在堆中申请对象内存的时候,
需要记得去释放。
但是有没有能让在堆中申请的内存自动释放呢?
当然有,就是我们的指针重载运算符可以实现。
我们可以设计一个智能指针,该指针指向我们
设计可用的对象,在使用完成后可以自动释放堆中的内存。
下面我们举例说明:
/****************************************************
* brief : 指针 -> * 运算符重载
* author : shao
* date : 2020-03-10
* note : none
*
****************************************************/
#include <iostream>
using namespace std;
class Person{
public:
int p_age;
int p_ID;
Person()
{
cout << "Person 的默认构造函数!" << endl;
this->p_age = 0;
this->p_ID = 0;
}
Person(int age, int ID)
{
cout << "Person 的有参构造函数!" << endl;
this->p_age = age;
this->p_ID = ID;
}
void showInfo()
{
cout << "p.age : " << this->p_age << ", p.ID : " << this->p_ID << endl;
}
~Person(