Re: Virtual functions and chaining up



On Thu, Jul 27, 2006 at 09:39:08AM +0200, David Nečas (Yeti) wrote:

Each class has its own class struct which contains all
ancestors's class structs

To clarify: The object system keeps an instance of both
MamanBarClass and MamanBarSubClass.  So the class structs
contains all ancestors' class structs, but the
MamanBarSubClass it gets in class_init() it its own.  When
it changes do_action()

    MamanBarClass mbclass = MAMAN_BAR_CLASS(klass);

    mbclass->do_action = maman_bar_sub_do_action;

it changes its own copy.

If the method does something in MamanBar itself it sets
do_action similarly

    klass->do_action = maman_bar_do_action_real;

where maman_bar_do_action_real() is the real implementation
of do_action() for MamanBarClass.  The purpose of
maman_bar_do_action() is to invoke do_action() of the right
class.  It can contain some code too, but this code is not
overridable.

Yeti


--
Anonyms eat their boogers.



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