I'm working on my own menu system in OpenGL. What I want is to have all my objects that are related to the menu in one vector, so I could easily just loop them all like this:
for (auto i : menuObjects)
{
i.checkInputs();
i.draw();
}
I've tried with other looping methods, even having this->draw();
inside the base class' function, but that obviously ended up in an infinite loop.
My base class is basically this:
class menuObject
{
public:
virtual void draw() { }
virtual void checkInputs() { }
};
And inherited classes are like this:
class Button : public menuObject
{
public:
void draw()
{
... drawing here ...
}
void checkInputs()
{
... checking inputs here ...
}
};
And here's how I save them in my vector:
std::vector<menuObject> menuObjects = {
Button(... parameters here ...)
};
It never goes to the overloaded function. I would rather not have every different menu object in their own vector. Any ideas? <3