![]() |
|
Inheritance - Printable Version +- iDevGames Forums (http://www.idevgames.com/forums) +-- Forum: Development Zone (/forum-3.html) +--- Forum: Game Programming Fundamentals (/forum-7.html) +--- Thread: Inheritance (/thread-1727.html) |
Inheritance - merrill541 - Feb 22, 2009 02:08 PM I have been trying to write a Constraint class, and then making other classes that inherit from it, but the virtual functions I defined in the original constraint class keep on being called, and not the ones in my derived class. Here is the code: Code: class GlobalConstraint{Inheritance - DoG - Feb 23, 2009 01:54 AM You need to declare them to be virtual in your subclasses, too. Inheritance - ozirus - Feb 23, 2009 04:18 AM As far as I know, it should not be necessary to redeclare the methods as virtual in the derived class. Once a method has been declared virtual, it will remain virtual in all derived classes. Nevertheless, I wrote the small code sample below in XCode to check this behavior: Code: class BaseThen running the following instructions properly called the derived func()... Code: Base * instance = new Derived();Do you have more code to share with us? Inheritance - merrill541 - Feb 23, 2009 07:29 AM I actually figured out what the problem was, I wasn't using a pointer for my classes. As in: Base * instance = new Derived(); I was using: Base instance; Derived d; instance = d; Sorry. Inheritance - ozirus - Feb 23, 2009 07:37 AM No problem
|