Question about inerithance

Let's suppose I have two classes, Tom and Jerry, both inerithing from a mother class Mother.
Is the following piece of code correct ?

Mother* m;
if (x == a) {
m = new Tom();
}
else if (x == b) {
m = new Jerry();
}

I thought it was not correct, but it seems to me to work.
It's called Polymorphism: every object B can be casted to an object A, provided that B "isA" A (thus A is the superclass of B).
http://www.cplusplus.com/doc/tutorial/polymorphism/
Thanks a lot Gaminic !
Now I understand this piece of code.
Topic archived. No new replies allowed.