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;
}
private:
int data;
};
B Play( B b)
{
return b ;
}
(1)
int main(int argc, char* argv[])
{
B t1 = Play(5); B t2 = Play(t1);
return 0;
}
(2)
int main(int argc, char* argv[])
{
B t1 = Play(5); B t2 = Play(10);
return 0;
}
森林海
相关分类