Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++: Error: Indirect nonvirtual base class is not allowed

I'm trying to create some sort of basic UI 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 a Button class that contains shared methods between all button types:

 class Button : public OGLRectangle

finally the class of ButtonBrowse inherits from this and contains methods for file opening:

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

Now would I be right in saying that to pass the parameters of the constructor in 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 the indirect nonvirtual error that's in the title?

like image 592
Brandon White Avatar asked Nov 20 '14 14:11

Brandon White


1 Answers

You need to call the constructor of Button, which will then call the OGLRectangle constructor.

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

As long as Button has its constructor set up to pass parameters up to its direct base class OGLRectangle, you should be fine.

like image 83
Lawrence Aiello Avatar answered Oct 05 '22 23:10

Lawrence Aiello