Posted by William D McQuain on April 19, 2001 at 17:30:29:
In Reply to: Inheritance and polymorphism posted by Nathan on April 19, 2001 at 17:03:11:
: If I declare a virtual function in lifeform class, say virtual void DoSomething(); and then declare another class Animal : public Lifeform with a function in it DoSomething();, I can't make it virtual because it can't instantiate the abstract class.
If an abstract base class Base declares a virtual function F(), pure or impure, a derived class Derived may override F(). The fact that Base is abstract places no limit on that.
Also, Derived::F() will be virtual automatically, whether you explicitly say so or not.
I need the derived classes of animal to access a virtual view function of animal.. The ways around this I see are to either make the stl list of type Animal rather than Lifeform, which loses Lifeform as my abstract base class, or to have Animal do some switch statements and search for the Animal that matches by name, then call the view function of that one directly, which doesn't use the advantages of polymorhpism.
: Can someone explain this one to me please?
Post a Followup