Victor Bazarov <v.Abazarov@comacast.net> wrote:
[color=blue]
> What is by your definition a "child" and what's a "parent"?
> Examples: the child class derives from the parent, or the parent
> class object contains a child object (or a pointer), or ???[/color]
No, I am talking about inheritance. `ChildClass' is derived from
`ParentClass'.
[color=blue][color=green]
>> | int ParentClass::runHandler (const char *tag, int a, char b)
>> | {
>> | HandlerType *handler = findMethod (tag);
>> | return (*handler) (a, b);[/color]
>
> So, how is 'HandlerType' defined? It seems that it's a pointer to
> a function. That suggests that 'fooHandler' and 'barHandler' are
> static member functions of 'ChildClass'. If not, please elaborate.[/color]
The snippet above tries to explain what I want in the end.
Thus, I did not define `HandlerType' in this context. Having a
proper definition for `HandlerType' so that it can be used to
call methods of a derived class in a base class, would actually
be a huge step towards solving my problem.
[color=blue][color=green]
>> In the real life problem, the code in the parent class is of
>> course much more complex. In the existing implementation this
>> is all done in the child classes, so that we got a lot of
>> unnecessary redundance in the code.[/color]
>
> I don't know what that all means. Is it really relevant?[/color]
Only for people asking the "this does not look like too much
redundancy, why do you want to go through all this?" question.
Strictly speaking it is not.
[color=blue][color=green]
>> The problem is that because different child classes would
>> define different numbers of such methods (and thus also of
>> different names) using abstract methods does not seem to help
>> here.[/color]
>
> What abstract methods? Whose abstract methods?[/color]
E.g. `virtual void method() = 0;' in the base class. Since the
derived classes would have to implement it the method can be
used in base class code.
[color=blue][color=green]
>> Has anybody managed to get something like this running?[/color]
>
> I am fairly certain that many folks have done something similar.
> However, you didn't specify enough to understand what to give as
> an example.[/color]
The problem is about generating different tree structures in
specific parsers which are all derived from a generic parser.
Experience has shown that many of the specific parsers look
pretty similar, so that I hope to put more intelligence into
the base class.
I would thus like to register handler methods for specific
attributes in the specific parsers which would then be called
in the generic one. Does that make more sense to you?
Cheers,
Martin
--
Yoda of Borg I am. Assimilated you will be.
-=-=- -=-=-=-=- --=-=-
Dipl. Ing. Martin Dietze -=-=-
http://www.the-little-red-haired-girl.org