I'm doing a menu in which each item open a different page. The id of the selected menu item correspond to the panel id. I think I'm doing it the wrong way but is it possible to do this like that :
class Panel
{
public:
const char* name;
int id;
Panel(const char* name, int id) : name(name), id(id) { }
};
class SpecialPanel1 : public Panel
{
SpecialPanel1(const char* name, int id) : Panel(name, id) { }
void draw()
{
//some code
}
};
class SpecialPanel2 : public Panel
{
SpecialPanel2(const char* name, int id) : Panel(name, id) { }
void draw()
{
//some code
}
};
int main()
{
int visiblePanel_id = 1;
//big array of various panels
Panel panels[2] = {
SpecialPanel1 ("", 1),
SpecialPanel2 ("", 2),
//....
};
for (Panel p : panels) {
if (p.id == visiblePanel_id) p.draw();
}
return 0;
}
I decided to put all the panels together in a array to make the code cleaner and avoid a switch statement but now I can't access to the draw function.