#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;
}
輸出:解釋這個C++代碼
Constructor called
Destructor called
Destructor called
構造函數被調用一次,而析構函數被調用兩次 這到底是怎麼happning?這是不確定的行爲?
它不是'運營商=' –
它不是賦值運算符,它與'運算符='相同, –