析构函数调用次数
#include <iostream>
using namespace std;
class A{ public: A(){cout<<"class A construtor"<<endl;} ~A(){cout<<"class A destrutor"<<endl;} void fun1(){cout<<"fun1()"<<endl;} }; int main() { A a; A a2=a; return 0; }
运行结果:
class A construtor
class A destrutor
class A destrutor
共调用2次析构函数,析构函数次数=构造函数次数+拷贝构造函数次数