Quote Originally Posted by mrjavoman View Post
When you assign a pointer of D to an pointer of Class A you are implicitly casting a D object to one of Class A thus you are striping the B Part of the inheritance and some of the functionality of Class D.

Implicit cast:
Code:
A* pA = pD;
you should always try to minimize casting especially with inheritance because it can lead you to a bunch of trouble
This is not true. Casting up is routinely done and is essential for any polymorphic code to work.
And this is casting of pointers and not objects. So, no object slicing takes place either.


if you use the first object and do this:
Code:
D* pD = new D;
pD->draw();
the compiler will give you an error and will say that draw is ambiguous, it has no way to decide which function to call
the solution for that is to specify the class with the scope resolution operator
something like this:
Code:
pD->A::draw();
Yes, that is true if he is calling Draw using pD, but he is calling it using pA, which is perfectly legal.

Here pA->draw() will call drawA defined in D, why? How'd system know which function should be called, drawA or drawB?
When you cast up, the compiler is going to treat the object D as object A. And since this function is virtual, it will point to the most recent override which is A1:raw, which in turn calls virtual function DrawA and which points to the most recent override of DrawA which is D:rawA.
So, that is why A1:raw gets called first followed by D:rawA.