This topic becomes more complex when you start having a lot of different derived classes. For example:
// Using structs so I don't have to write public everywhere - and only relevant data includedstruct Base{ virtual void Update() = 0;};struct Derived1 : Base{ void Update() {DoDerived1Stuff();}; void DoDerived1Stuff(); };struct Derived2 : Base{ void Update() {DoDerived2Stuff();}; void DoDerived2Stuff();}; // Somewhere elsestd::vector<Base*> MyObjects;// Push lots of different Derived1 and Derived2 objects onto MyObjects// Note that at compile time you don't know what order the objects are in// i.e. : is MyObjects[0] a Derived1 or Derived2?// Method1: MyObjects[0]->Update();// Method2: if(Derived1* thisObject = dynamic_cast<Derived1*>(MyObjects[0]) thisObject->DoDerived1Stuff; if(Derived2* thisObject = dynamic_cast<Derived2*>(MyObjects[0]) thisObject->DoDerived2Stuff;
The problem with using a C-style cast is that it will cast your data to the requested type, no matter what, and to hell with the consequences - it's up to the programmer to ensure that's they're casting to the right type. A C++ dynamic_cast will only succeed if the object being cast to is actually that type of object, as follows:
Base* base = new Base;Derived1* thisOb = dynamic_cast<Derived1*>(base); //failsBase* base = new Derived1;Derived1* thisOb = dynamic_cast<Derived1*>(base); //succeedsBase* base = new Derived2;Derived1* thisOb = dynamic_cast<Derived1*>(base); //fails
The code is now type-safe, which it isn't necessarily with a straight C-style cast.
The preferred option with many folks in C++ is to use a virtual function (ie Method 1), which you've already hinted at using. Dynamic_casts are seen as a second-string approach and are commonly seen as indicating a design flaw.
Oh, and btw - derived classes should be a type of their base-class - it models an 'is-a' relationship. Unless genetics has changed recently a son isn't likely to become a kind of mother [smile]. A better approach might be to have a Person abstract class, from which both Mother and Son are derived.
HTH,
Jim.
Edit : ignore my Mother/Son guff - I just re-read your post, and you're obviously using them as surrogates for a different inheritance-chain. Sorry!