Deriving from interface implementation



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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]