Virtual functions and chaining up
- From: Nikhil Dinesh <nikhild seas upenn edu>
- To: gtk-app-devel-list gnome org
- Subject: Virtual functions and chaining up
- Date: Thu, 27 Jul 2006 02:24:23 -0400
Hi,
I'm trying to create my own object hierarchy, and I don't
understand the part in the API reference about virtual
functions and chaining up. To create a virtual public
method, the docs say we need to do something like:
/* declaration in maman-bar.h. */
struct _MamanBarClass {
GObjectClass parent;
/* stuff */
void (*do_action) (MamanBar *self, /* parameters */);
};
void maman_bar_do_action (MamanBar *self, /* parameters */);
/* implementation in maman-bar.c */
void maman_bar_do_action (MamanBar *self, /* parameters */)
{
MAMAN_BAR_GET_CLASS (self)->do_action (self, /* parameters */);
}
I assume that the subclass definition looks like:
struct _MamanBarSubClass {
MamanBarClass parent;
....
void (*do_action) (MamanBarSub* self, /* params */);
}
If the maman_bar_do_action actually needs to do something, and
the derived class needs to chain up, wouldn't it result in another
invocation of maman_bar_do_action which is again redirected to
the derived class? This would of course result in an infinite loop.
Please clarify.
Thanks,
-Nikhil
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]