PDA

View Full Version : Virtual Functions and Inheritance?


Shawn Curry
10-15-2002, 07:16 AM
Ok next question. I know that when I declare a pure virtual function in a class, I have to make sure to provide a def. for it in all the classes I derive from it, or that class is also an abstract class. Ok say I derive a class from that class and define that function. Now I derive another class from the second class, but its similar enough that I can use definition of that function from the second class. Do I still have to define that function in the final class, since the first class is it's indirect base? Or will the definition from the second class work?

Thanks

fivesidecube
10-15-2002, 09:46 AM
Shawn,

Just to make sure I got this right. You have ClassA that has a pure virtual function, ClassB that derives from ClassA and defines all the pure virtual functions in ClassA and ClassC that derives from ClassB.

If this is the case, then you can create instances of both ClassB and ClassC as the pure virtual function from ClassA is defined by ClassB's implementation.

Shawn Curry
10-15-2002, 07:55 PM
Yep that's the one!

Thanks