PRACTICE QUIZ: Constructor, Destructor, Copy Constructor

Assume the following class declaration:

	class X {
		int p; 
		...
	public:
		X( int p1 ) : p(p1) { ... }
		X ( const X&  x1 ) { ... }
		X& operator= (const X&  x2 ) { ... }
		... // member functions etc.
		void merge ( X x3 ) { .... } 
	};
For each line of code below, indicate if the line is legal, what extra methods are required of class X to make it legal if it is not, and what methods of class X will be invoked in each case.

	X  a( 10 ), a1( 100 );


	X  b;


	X  c =  12;


	X  c1 =  a1;


	X  d( a );


	X  e( 5, 18 );


	cout << a.p + a1.p << endl;


	a1 = a;


	d.merge( a );


	X  arr[ 15 ];


	X  f  =  X( -1 ) *  X ( -2 );

Hint: The last example creates two unnamed temporary objects of class X, and then does a lot more!