Re: Are vtables of interfaces always correctly initialized?
- From: Kjell Ahlstedt <kjell ahlstedt bredband net>
- To: gtkmm-list gnome org
- Subject: Re: Are vtables of interfaces always correctly initialized?
- Date: Sun, 12 Jun 2011 19:57:12 +0200
Let's see if I can clarify the reasoning in my previous message. I
continue to use GooCanvas classes as an example, but now I'll turn to a
syntax that resembles Java. The rules for inheritance hierarchies in
C/GObject are more like Java than like C++: Only single inheritance
between classes, but in addition to inheritance from a base class, a
class can implement zero or more interfaces.
public interface GooCanvasItem;
public class GooCanvasItemSimple implements GooCanvasItem;
public class GooCanvasRect extends GooCanvasItemSimple implements
GooCanvasItem;
The repetition of "implements GooCanvasItem" in GooCanvasRect is perhaps
not like Java, but it's GObject's way of overriding virtual functions
declared in the interface.
When gmmproc generates C++ wrappers for these entities,
g_type_register_static() and g_type_add_interface_static() are called
with the following results:
Goocanvas::Item
No new type registered, no interface added.
Goocanvas:Item effectively renames GooCanvasItem,
and defines C++ virtual functions.
Goocanvas::ItemSimple
public class gtkmm__GooCanvasItemSimple extends GooCanvasItemSimple
implements GooCanvasItem;
Goocanvas::Rect
public class gtkmm__GooCanvasRect extends GooCanvasRect;
I suspect that gtkmm__GooCanvasRect shall also implement GooCanvasItem,
i.e. Goocanvas::Item::add_interface(get_type()) shall be called from
Goocanvas::Rect_Class::init().
Otherwise the C++ virtual functions in Goocanvas::Item are never called
in a class derived from Goocanvas::Rect. Since gtkmm__GooCanvasRect is
not derived from gtkmm__GooCanvasItemSimple, gtkmm__GooCanvasRect
(Goocanvas::Rect) does not inherit the implementation of GooCanvasItem
functions defined in gtkmm__GooCanvasItemSimple (Goocanvas::ItemSimple).
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]