C ++: Error: indirect non-virtual base class not allowed

I am trying to create some kind of basic user interface in C ++ and OpenGL. With this, I am using a class called OGLRectangle:

class OGLRectangle : public Renderable, public Listener
{
public:
                    OGLRectangle();
                    OGLRectangle(float cX, float cY);
                    ~OGLRectangle();
...
}

      

this is inherited by the Button class, which contains common methods between all types of buttons:

 class Button : public OGLRectangle

      

Finally, the ButtonBrowse class inherits from this and contains methods for opening the file:

class ButtonBrowse : public Button
{
    public:
        ButtonBrowse(float cX, float cY);
...
}

      

Now, I would be right to say that in order to pass constructor parameters to ButtonBrowse, I need to do something like this in the constructor:

ButtonBrowse::ButtonBrowse(float cX, float cY) : OGLRectangle(cX, cY)
{
...
}

      

and if so why am I getting an indirect non-virtual error in the header?

+3


source to share


1 answer


You need to call the constructor Button

, which will then call the constructor OGLRectangle

.

ButtonBrowse::ButtonBrowse(float cX, float cY) : Button(cX, cY)
{
...
}

      



As long as Button

has its constructor set up to pass parameters to its direct base class OGLRectangle

, you should be fine.

+5


source







All Articles