1== T t2(t1); { T t3=t2; }
#include <iostream>
using namespace std;
class T
{
int x;
public:
T(int xx) { x=xx; cout<<"constructor: "<<x<<endl; }
~T( ) { cout<<"destructor: " <<x<<endl; }
T(T &t) { x=t.x+99; cout<<"copy constructor: "<<x<<endl; }
};
int main()
{
T t1(10);
T t2(t1);
{ T t3=t2; }
cout<<"****************************\n";
}
2== void disp(T t) { cout<<t.get_x()<<endl;} disp(t1);
#include <iostream>
using namespace std;
class T
{ int x;
public:
T( int xx ) { x=xx; cout<<"constructor: "<<x<<endl; }
~T( ) { cout<<"destructor: "<<x<<endl; }
T(T &t) { x=t.x+99; cout<<"copy constructor: "<<x<<endl; }
int get_x() { return x;}
};
void disp(T t)
{ cout<<t.get_x()<<endl;}
int main( )
{ T t1(10);
disp(t1);
cout<<"****************************\n";
}
#include <iostream>
using namespace std;
class T
{
int x;
public:
T(int xx) { x=xx; cout<<"constructor: "<<x<<endl; }
~T( ) { cout<<"destructor: "<<x<<endl; }
T(T &t) { x=t.x+99; cout<<"copy constructor: "<<x<<endl; }
int get_x() { return x;}
};
T f( )
{ T t(100);
return t; }
int main()
{
T t1(10);
t1=f();
cout<<"****************************\n";
}