Original Post
I''m aware you can''t declare data virtual but I''m looking for something to do something similar to "virtual static const"
I''m writing a GUI class and everything is derived from a widget, and every listbox, button, window has a parent (NULL if parent is the global context) as well as a list of children. Classes like Buttons are not designed to have children, and I wanted a way to detect if somebody tries to create a widget using a non-container class as a parent.
then in the constructor
I have thought of one way to do this, but it seems hackish, and I was wondering if anybody had any cleaner suggestions for me.
class Widget
{
private:
Widget *mParent;
WidgetList mChildren;
public:
Widget(Widget *parent=NULL);
//and here''s what I wanted to add
virtual static const bool CanParent;
};
TextBox::TextBox(Widget *parent)
{
if(parent && parent->CanParent)
mParent = parent;
else
mParent = NULL;
}