#include<iostream>
using namespace std;
class C{
public:
C(
int i ){ cout << "constructor" << endl; }
C(
const C& c ){ cout << "copy" << endl; }
C&
operator = (
const C& c ){ cout << "=" << endl; }
private:
};
C fun(){
return C(2);
}
int main(){
C c( fun() );
}
/*
constructor
请按任意键继续. . .
*/没有调用拷贝构造函数编译器做了优化,C c( fun() )->C c(C(2))。构造两个同样的构造函数,
其中一个是没用的临时对象,编译器就直接把它转化为C c(2),