Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changes between Initial Version and Version 1 of code/howto/Super


Ignore:
Timestamp:
Oct 10, 2008, 4:03:54 AM (11 years ago)
Author:
landauf
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • code/howto/Super

    v1 v1  
     1= HowTo: Super =
     2[[TracNav(TracNav/TOC_Development)]]
     3
     4== Description ==
     5SUPER is a macro defined in {{{core/Super.h}}}. It's capable to call a function in the parent class of another class. This avoids class-hierarchy-dependend code like {{{MyParentClass::function();}}}. Instead we use {{{SUPER(MyClass, function);}}}. As you can see, the super-call depends only on the current class. If the parent changes, we don't have to modify the code.
     6
     7'''Important''': A super-function must be virtual and public. If you don't declare the function {{{public}}} you'll get a compiler error complaining about the private nature of the function.
     8
     9[wiki:Super] explains in detail how to add a new super-function.
     10
     11== Usage ==
     12This is how you call the SUPER macro:
     13 * '''SUPER('''''MyClass, functionname, arguments...''''')''';
     14''MyClass'' is the name of the class implementing this function.[[br]]
     15''functionname'' is the name of the super-function.[[br]]
     16''arguments'': The arguments passed to the function. If the function takes no arguments, SUPER gets called with only 2 parameters (''MyClass'' and ''functionname'').
     17
     18== Example ==
     19This is an example how to use SUPER:
     20
     21*.h file:
     22{{{
     23#include "core/BaseObject.h"
     24
     25class MyClass : public BaseObject
     26{
     27    public:
     28        virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     29};
     30}}}
     31
     32*.cc file:
     33{{{
     34void MyClass::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     35{
     36    SUPER(MyClass, XMLPort, xmlelement, mode);
     37
     38    doSomething();
     39    ...
     40}
     41}}}