M
maverik
Hi all.
I have some class that contains only pure virtual functions (class-
interface):
class IButton {
// Contents of the class
};
So when I actually implement some type of button I do it like this
class ImageButton : public IButton {
// Contents of the class
};
It allows me to create a container of buttons without knowledge about
button types that this container would hold:
std::vector<IButton *> m_buttons;
The problem is: when I add some specific function to the inherited
button class then I can call it only in this way:
((ImageButton *)m_buttons)->SetImage(...); // I know that i-th
button is typeof ImageButton
Looks ugly a little bit, isn't it?
Of course I can add this specific function to the base class (IButton)
class IButton {
void SetImage(...) = 0;
};
but in this case IButton becomes just a bunch of methods from
different classes.
Is there a way to make it better?
Thanks.
I have some class that contains only pure virtual functions (class-
interface):
class IButton {
// Contents of the class
};
So when I actually implement some type of button I do it like this
class ImageButton : public IButton {
// Contents of the class
};
It allows me to create a container of buttons without knowledge about
button types that this container would hold:
std::vector<IButton *> m_buttons;
The problem is: when I add some specific function to the inherited
button class then I can call it only in this way:
((ImageButton *)m_buttons)->SetImage(...); // I know that i-th
button is typeof ImageButton
Looks ugly a little bit, isn't it?
Of course I can add this specific function to the base class (IButton)
class IButton {
void SetImage(...) = 0;
};
but in this case IButton becomes just a bunch of methods from
different classes.
Is there a way to make it better?
Thanks.