Hi there,
I need to build a class that the user should be able to use as a Gtk::Widget (basically to put it inside of a window). Let's say that for building my widget I'll need it to be a Gtk::VBox, which also inherits from Gtk::Widget.
Now, I could inherit my new class directly from Gtk::VBox, the user would then be able to use it just like a Gtk::Widget, and I would be able to make my implementation without a lot of trouble. The problem with this is that the user would be able to use public members of Gtk::VBox, but I don't want him to!
1 2 3 4
|
class MyClass : public Gtk::VBox {
...
}; // Oh my! The end-user could use MyClass like a Gtk::VBox!
|
My ideal solution would be:
- MyClass inherits from Gtk::Widget (public) : the end-user can therefore use MyClass just like a Gtk::Widget.
- MyClass ingerits from Gtk::VBox (private) : the end-user cannot use methods from Gtk::VBox.
- For a MyClass object there have to be one and only one instance of Gtk::Widget
So, reminding something about virtual classes, the basic idea would have been:
1 2 3 4
|
class MyClass : public virtual Gtk::Widget, private Gtk::VBox {
...
};
|
Another concern that blows my mind is about the implementation of Gtk::VBox : it does inherit from Gtk::Widget in a public fashion (i.e. not virtually). As a consequence I don't think the solution I come up with would work at all.
What do you think about?
EDIT: I forgot something: the Gtk::Widget object the user is referring to when using an instance of MyClass has to be the same which Gtk::VBox inherits from! (that's why I've put
virtual
there)