析构用于释放构造函数中初始化的数据成员
析构不能重载
析构函数格式
#include "iostream"
using namespace std;
extern "C"
{
#include "string.h"
}
class rlxy
{
public:
int a;
rlxy(int a, int b, const char *c)
{
this->c = new char[1024];
strcpy(this->c, c);
cout << c << endl;
}
~rlxy()
{
cout << "xg" << endl;
delete[] c;
}
protected:
int b;
private:
char *c;
};
int main()
{
rlxy ss(20, 30, "rlxy");
}