各種構造函數的調用

#include<iostream>
using std::cout;
using std::endl;
class Base
{
protected:
int value;
public:
	Base(int i):value(i)
{
cout<<" Base"<<endl;
}
	Base()
{
cout<<" default Base"<<endl;
}		
	Base(Base &b)
{
	value=b.value;
cout<<" Base &"<<endl;
}	
	~Base()
{
cout<<" ~Base"<<endl;
}
Base& operator = (const Base&b)
	{
		cout<<"="<<endl;
	value=b.value;
	return *this;
	}

};

Base play(Base b)
{return b;}
int main()
{
Base temp;
temp=play(5);
return 0;
}

 
當主函數爲
int main()
{
Base temp=play(5);
return 0;
}
輸出爲
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章