0

I feel like total dumb on this one. I want to create a subclass of my class Model:

class Model {
public:
    Model(const GLchar* path, const GLuint& amountLoaded);
protected:
    void loadModel();
};

It should look like this:

class AnimatedModel : public Model {
public:
    AnimatedModel(const GLchar * path, const GLuint & amountLoaded);
protected:
    /*Override!*/
    void loadModel();
};

Then, form the outside, I want to create a new AnimatedModel. The AnimatedModel contructor simply passes its arguments to the Model constructor. The Model constructor then calls the Method loadModel(). I hoped, that this call would then reach my overridden version of this method, but it doesn't seem to work like this... What am i missing here?

Erik Brendel
  • 683
  • 9
  • 23
  • Also read this: https://isocpp.org/wiki/faq/strange-inheritance#calling-virtuals-from-ctors – Revolver_Ocelot May 31 '16 at 22:42
  • @Erik, you need set: `virtual void loadModel();` on Model class – David Isla May 31 '16 at 22:44
  • @Revolver_Ocelot Oh yes, you're right. I didn't know about that. thanks for clarification – Erik Brendel May 31 '16 at 22:54
  • 2
    A quick and easy way to spot this problem in a larger codebase, btw, is to use the `override` keyword in the derived class function signature - if the signature of the base class method you're overriding doesn't match (or if it's not `virtual` in the base) then the compiler will give you a clear error. – sjrowlinson May 31 '16 at 22:56

0 Answers0