C++基础 -12- 类的析构函数
———————标准输入输出———————
🎈析构用于释放构造函数中初始化的数据成员
🎈析构不能重载
🎄析构函数格式(图片+代码段)

#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");
}
———————End———————

浙公网安备 33010602011771号