怎么会这样?求助
小白在此 2014-04-17 02:27:06 #include <iostream>
using namespace std;
class base {
int n;
public:
base (){cout<<"Initializing default\n";}
base(int m){ cout<<"Initializing\n";n=m;}
~base(){cout<<"Destroying\n";}
void output();
};
void base::output()
{
cout << n << endl;
}
int main()
{
base x=1;
base y=x;
return 0;
}
问题来了,第一我没见过base x = 1这种用法,但是,竟然可以,第二,为什么base y = x不调用构造函数?而写成base y; y =x就会调用构造函数,是编译器优化的结果吗?编译器到底是怎么实现的呢?