Gtk::Widget as virtual base

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Gtk::Widget as virtual base

jyotirmoy bhattacharya
I want to use an abstract class derived from Gtk::Widget and then
derive different classes which use particular widgets to display themselves.

That is, I want to do something like

class vwidget: public virtual Gtk::Widget
{
 public:
  virtual void magic()=0;
};

class mywidget: public vwidget, public Gtk::HBox
{
 public:
  void magic() {x=1;}
 private:
  int x;
};

mywidget m;

But when I compile this I get the following errors:
document.h:86: error: no unique final overrider for `virtual void Glib::ObjectBase::destroy_notify_()' in `mywidget'
document.h:86: error: no unique final overrider for `virtual void Glib::ObjectBase::set_manage()' in `mywidget'
document.h:86: error: no unique final overrider for `virtual void Glib::ObjectBase::destroy_notify_()' in `mywidget'
document.h:86: error: no unique final overrider for `virtual void Glib::ObjectBase::set_manage()' in `mywidget'

I am using gtkmm 2.4 and g++ 3.4.2

Not making Gtk::Widget virtual in the definition of vwidget leads to the same errors and
I don't think that would solve my problem anyway.

I would be grateful if the subscribers of this list can suggest a way out of my problem.

--Jyotirmoy

_______________________________________________
gtkmm-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: Gtk::Widget as virtual base

Antonio Coralles
jyotirmoy bhattacharya wrote:

> I want to use an abstract class derived from Gtk::Widget and then
> derive different classes which use particular widgets to display
> themselves.
>
> That is, I want to do something like
>
> class vwidget: public virtual Gtk::Widget
> {
>  public:
>   virtual void magic()=0;
> };
>
> class mywidget: public vwidget, public Gtk::HBox
> {
>  public:
>   void magic() {x=1;}
>  private:
>   int x;
> };
>
> mywidget m;
>
> But when I compile this I get the following errors:
> document.h:86: error: no unique final overrider for `virtual void
> Glib::ObjectBase::destroy_notify_()' in `mywidget'
> document.h:86: error: no unique final overrider for `virtual void
> Glib::ObjectBase::set_manage()' in `mywidget'
> document.h:86: error: no unique final overrider for `virtual void
> Glib::ObjectBase::destroy_notify_()' in `mywidget'
> document.h:86: error: no unique final overrider for `virtual void
> Glib::ObjectBase::set_manage()' in `mywidget'
>
The problem is that Gtk::HBox is also an Gtk::Widget and thus for
example Gtk::Hbox has methods like Gtk::Widget like set_manage(),
destroy_notify_(), ... . How can the compiler know if you want to use
Gtk::Widget::set_manage() or Gtk::HBox::set_manage() in your mywidget
class ? If you really want to do this, you have to make that decission
yourself for every method the compiler complains about.

class mywidget: public vwidget, public Gtk::HBox
{
 public:
  void magic() {x=1;}

  // this are unique final overriders
  void destroy_notify() { vwwidget::destroy_notify(); }
  void set_manage() { Gtk::HBox::set_manage(); }
  // ....
 
 private:
  int x;
};

Maybe may also be interested in
http://www.parashift.com/c++-faq-lite/multiple-inheritance.html#faq-25.11.

Hope this helps,
Antonio

> I am using gtkmm 2.4 and g++ 3.4.2
>
> Not making Gtk::Widget virtual in the definition of vwidget leads to
> the same errors and
> I don't think that would solve my problem anyway.
>
> I would be grateful if the subscribers of this list can suggest a way
> out of my problem.
>
> --Jyotirmoy
> _______________________________________________
> gtkmm-list mailing list
> [hidden email] <mailto:[hidden email]>
> http://mail.gnome.org/mailman/listinfo/gtkmm-list
>
> ------------------------------------------------------------------------


_______________________________________________
gtkmm-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: Gtk::Widget as virtual base

Antonio Coralles
In reply to this post by jyotirmoy bhattacharya
Antonio Coralles wrote:

> jyotirmoy bhattacharya wrote:
>
>> I want to use an abstract class derived from Gtk::Widget and then
>> derive different classes which use particular widgets to display
>> themselves.
>>
>> That is, I want to do something like
>>
>> class vwidget: public virtual Gtk::Widget
>> {
>>  public:
>>   virtual void magic()=0;
>> };
>>
>> class mywidget: public vwidget, public Gtk::HBox
>> {
>>  public:
>>   void magic() {x=1;}
>>  private:
>>   int x;
>> };
>>
>> mywidget m;
>>
>> But when I compile this I get the following errors:
>> document.h:86: error: no unique final overrider for `virtual void
>> Glib::ObjectBase::destroy_notify_()' in `mywidget'
>> document.h:86: error: no unique final overrider for `virtual void
>> Glib::ObjectBase::set_manage()' in `mywidget'
>> document.h:86: error: no unique final overrider for `virtual void
>> Glib::ObjectBase::destroy_notify_()' in `mywidget'
>> document.h:86: error: no unique final overrider for `virtual void
>> Glib::ObjectBase::set_manage()' in `mywidget'
>>
> The problem is that Gtk::HBox is also an Gtk::Widget and thus for
> example Gtk::Hbox has methods like Gtk::Widget like set_manage(),
> destroy_notify_(), ... . How can the compiler know if you want to use
> Gtk::Widget::set_manage() or Gtk::HBox::set_manage() in your mywidget
> class ? If you really want to do this, you have to make that decission
> yourself for every method the compiler complains about.
>
> class mywidget: public vwidget, public Gtk::HBox
> {
>  public:
>   void magic() {x=1;}
>
>   // this are unique final overriders
>   void destroy_notify() { vwwidget::destroy_notify(); }
>   void set_manage() { Gtk::HBox::set_manage(); }
>   // ....
>  
>  private:
>   int x;
> };
>
> Maybe may also be interested in
> http://www.parashift.com/c++-faq-lite/multiple-inheritance.html#faq-25.11.
>
> Hope this helps,
> Antonio

Maybe you can resolve most of this ambiguitys with using virtual
inheritance.  The problem is,  that  [  keyword diamond inheritance ]
for doing this, both classes you inherit from should use virtual
inhertitance from Gtk::Widget. I guess this is not the case for
Gtk::HBox, so using virtual inheritance for vwwidget only doesn't help.
Maybe there is an easier way to do what you want to do ...
Antonio

>
>> I am using gtkmm 2.4 and g++ 3.4.2
>>
>> Not making Gtk::Widget virtual in the definition of vwidget leads to
>> the same errors and
>> I don't think that would solve my problem anyway.
>>
>> I would be grateful if the subscribers of this list can suggest a way
>> out of my problem.
>>
>> --Jyotirmoy
>> _______________________________________________
>> gtkmm-list mailing list
>> [hidden email]
> <mailto:[hidden email]> <mailto:[hidden email]>
>> http://mail.gnome.org/mailman/listinfo/gtkmm-list
>>
>> ------------------------------------------------------------------------
>
>
> _______________________________________________
> gtkmm-list mailing list
> [hidden email] <mailto:[hidden email]>
> http://mail.gnome.org/mailman/listinfo/gtkmm-list


_______________________________________________
gtkmm-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtkmm-list
Reply | Threaded
Open this post in threaded view
|

Re: Gtk::Widget as virtual base

jyotirmoy bhattacharya
Thanks for your interest.

> Maybe you can resolve most of this ambiguitys with using virtual
> inheritance.  The problem is,  that  
>[  keyword diamond inheritance ]
> for doing this, both classes you inherit from should use virtual
> inhertitance from Gtk::Widget. I guess this is not the case for
> Gtk::HBox, so using virtual inheritance for vwwidget only doesn't >help.
Why dosen't gtkmm make Gtk::Widget a virtual base of widgets
like Gtk::Hbox? I can't think of any programs that
might by broken by such a change but being a gtkmm newbie
I really don't know.

> Maybe there is an easier way to do what you want to do ...
The workaround that I am using at present is

class vwidget
{
  public:
    virtual void magic()=0;
    virtual Gtk::Widget *get_widget()=0;
};

class mywidget: public vwidget
{
  public:
    void magic() {x=1;}
    Gtk::Widget *get_widget() {return &box;}
  private:
    int x;
    Gtk::Hbox box;
};

But besides being inelegant, this is a maintenance problem
since the actual class corresponding to mywidget is displayed
by using a large hierarchy of widgets and everytime I change
the root of that hierarchy I have to remember to update
get_widget(). If I forget to do so the mistake is not caught during
compilation and leads to obscure runtime errors.
_______________________________________________
gtkmm-list mailing list
[hidden email]
http://mail.gnome.org/mailman/listinfo/gtkmm-list