#include <iostream>
using namespace std;
class A
{
int n;
public:
A()
{
cout << "Constructor called" << endl;
}
~A()
{
cout << "Destructor called" << endl;
}
};
int main()
{
A a; //Constructor called
A b = a; //Constructor not called
return 0;
}
输出:
Constructor called
Destructor called
Destructor called
构造函数被调用一次,而析构函数被调用两次 这里发生了什么?这是未定义的行为吗?