Re: Deriving from interface implementation
- From: Sergey Smirnykh <sergey smirnykh siborgium xyz>
- To: Kjell Ahlstedt <kjellahlstedt gmail com>
- Cc: "gtkmm-list gnome org" <gtkmm-list gnome org>
- Subject: Re: Deriving from interface implementation
- Date: Thu, 5 Aug 2021 19:38:05 +0700
Thank you!
On Wed, 4 Aug 2021 19:19:36 +0200
Kjell Ahlstedt <kjellahlstedt gmail com> wrote:
Glib::ObjectBase is a virtual base class. The constructor of a
virtual base class is called from the most derived class. When
ModelImpl is the most derived class, its constructor calls
Glib::ObjectBase(typeid(ModelImpl)). When Derived is the most derived
class, Glib::ObjectBase(typeid(ModelImpl)) is not called. Instead
ObjectBase's default constructor is called from Derived's
constructor. That's not what you want in this case. You must call the
right ObjectBase constructor from Derived's constructor, like
class Derived: public ModelImpl
{
Derived()
: Glib::ObjectBase(typeid(Derived)),
ModelImpl() {}
};
Den 2021-08-04 kl. 12:15, skrev Sergey Smirnykh via gtkmm-list:
Hello!
I've run into the issue I can't resolve on my own. I have
a Gio::ListModel implementation and a (C++) class derived
from said implementation.
Calling G_IS_LIST_MODEL(gobj) on the implementation's gobj returns
1. However, G_IS_LIST_MODEL(gobj) on the derived class's gobj
returns 0.
How to make inheritance work? I've been unable to find any
guides/tutorials on this issue, hence the question.
The implementation is defined as follows:
class Item { ... }
class ModelImpl: public Gio::ListModel, public Glib::Object {
public: ModelImpl(): Glib::ObjectBase(typeid(ModelImpl)),
Gio::ListModel() {}
virtual ~ModelImpl() = default;
protected:
std::vector<Item*> items;
GType get_item_type_vfunc() override {
return Item::get_type();
}
guint get_n_items_vfunc() override {
return items.size();
}
gpointer get_item_vfunc(guint position) override {
if (position < items.size()) {
return items[position]->gobj();
}
return nullptr;
}
};
And the derived class:
class Derived: public ModelImpl {
Derived(): ModelImpl() {}
}
Thanks in advance!
Sergey Smirnykh
_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
https://mail.gnome.org/mailman/listinfo/gtkmm-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]