12.3.1. Polymorphism: Test Yourself

Study the following two classes (the ellipses denote code omitted for simplicity), the four object instantiations, the assignment at the top of main, and the twelve function calls. Determine to which function each call binds (the function defined in the Parent or Child class). In a temporary file or on paper, fill in the twelve blanks with either "Parent" or "Child," indicating which class the function call binds. There is a link to the answers at the bottom of the page.

class Parent
{
    public:
		void funcA() { . . . }
	virtual	void funcB() { . . . }
		void funcC() { . . . }
};


class Child : public Parent
{
    public:
		void funcA() { . . . }
	virtual	void funcB() { . . . }
};


int  main()
{
	Parent*	P1 = new  Parent;
	Parent*	P2 = new  Child;
	Child*	C1 = new  Child;
	Child	temp;
	Parent	P3 = temp;


	P1->funcA();		// (a)_______________
	P1->funcB();		// (b)_______________
	P1->funcC();		// (c)_______________

	P2->funcA();		// (d)_______________
	P2->funcB();		// (e)_______________
	P2->funcC();		// (f)_______________

	C1->funcA();		// (g)_______________
	C1->funcB();		// (h)_______________
	C1->funcC();		// (i)_______________

	P3.funcA();		// (j)_______________
	P3.funcB();		// (k)_______________
	P3.funcC();		// (l)_______________

	return 0;
}

Solution