I have the to GLib classes Foo and DerivedFoo.
The Foo class has a bar () method:
typedef struct _FooClass
{
GObjectClass parent_class;
void (*bar) (Foo *self);
} FooClass;
The DerivedFoo class derives from Foo and implements the bar () method:
void derived_foo_bar (DerivedFoo *self);
static void
derived_foo_class_init (DerivedFooClass *klass)
{
FooClass *foo_class = FOO_CLASS (klass);
// Compiler warning appears here
foo_class->bar = derived_foo_bar;
}
The warning message is:
warning: assignment from incompatible pointer type
The pointers are not compatible, because the type of the self parameter is different (Foo * vs. DerivedFoo *).
Is this the right way to implement virtual methods in GObject?
If so, can/should I do something about the compiler warning?