#include 

class X {
	private:
		int *x;
	public:
		X();
		~X();
};

class Y : public X {
	private:
		int *y;
	public:
		Y();
		~Y();
};
		

// constructor for X
X::X() 
{ 
	cout << "X::X()" << endl; 
	x = new int; 
}

// destructor for X
X::~X() 
{
	cout << "X::~X()" << endl;
	delete x;
};


// constructor for Y 
Y::Y() 
{ 
	cout << "Y::Y()" << endl; 
	y = new int; 
}

// destructor for Y
Y::~Y() 
{
	cout << "Y::~Y()" << endl;
	delete y;
};


int main () {
	X *xptr;
	
	xptr = new Y();
	delete xptr;	// note that xptr points to an object of class Y

	return 0;
}

See the output of this program