#include <iostream>
#include <string>
using namespace std;
class Cc
{
public:
Cc(const Cc& c)
{
cout<<"b"<<endl;
m_str=c.m_str;
}
Cc(string str)
{
cout<<"a"<<endl;
m_str=str;
}
Cc operator+(const string& str)
{
return Cc(m_str+str);
}
private:
string m_str;
};
int main()
{
Cc a("1");
Cc b("2");
Cc c(a+"1");
cout << sizeof(Cc) << endl;
return 0;
}
无名对象使调用构造函数的次数减少,优化程序