仔细研究一下下面程序的输出,体会拷贝构造函数和赋值构造函数的调用时机
#include <iostream> using namespace std; class B { public: B() { cout<<"default constructor"<<endl; } ~B() { cout<<"destructed"<<endl; } B(int i):data(i) //B(int) works as a converter ( int -> instance of B) { cout<<"constructed by parameter " << data <<endl; } B(const B& b) { cout<<"Copy Constructor"<<endl; } B& B::operator =(const B& b) { cout<<"Assignment Constructor"<<endl; data = b.data; return *this; } private: int data; }; B Play( B b) { return b ; } int main(int argc, char* argv[]) { B t1 = Play(5); //B t2 = Play(t1); B t2 = Play(10); return 0; }