Re: pointer to a method
From: David White (no.email_at_provided)
Date: 10/24/03
- Next message: Dennis Handly: "Re: Template instantiation on HP aCC compiler"
- Previous message: Stephen Baynes.: "Re: Spell-checking source code"
- In reply to: Woodster: "Re: pointer to a method"
- Next in thread: Nirus: "Re: pointer to a method"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 24 Oct 2003 22:03:10 +1000
"Woodster" <mirror@127.0.0.1> wrote in message
news:MPG.1a0349792aba9000989681@news.westnet.com.au...
> I was trying to do something similar where I have several derived
> classes each containing it's own specific member variables.
>
> I am trying to construct a report consisting of values extracted from my
> derived classes, where the report is entered as XML and I just extract
> custom tags and replace them with a value. The way I wanted to do this
> was to construct a list of name-value pairs, where the name is the tag I
> am searching for and the value is a pointer to a method from one of the
> derived classes. I do not know which classes the values will be coming
> from until I reach the desired tag.
>
> How would/should I declare a structure that will simply store a string
> value (char *) and a function * as required so I couold call a specific
> class method based on one of these string values?
A pointer-to-member is specific to a single class (the class named in the
pointer's declaration), so you can't have a Base::* pointing to a member of
Derived. However, if all value member functions are declared virtual in
Base, you could do everything with pointers-to-members of Base.
Otherwise, you could associate each name with a proxy object or function,
and the proxy can call the appropriate member function of the appropriate
class of object. For example, the hierarchy proposed in Rolf Magnus's reply
could be used as a proxy hierarchy if it's not suitable as the value
hierarchy itself. Each class's override would have a hard-wired call to a
specific member function of a member object of the appropriate derived
class. That's more trouble than I'd like to go to if I could avoid it,
though.
A cruder, un-OO, approach is to associate each name with an enum. A switch
on the enum would then call the appropriate member function. This would get
messy if an object pointer needed to be kept along with the enum, because
you'd have to cast the pointer to the correct derived-class pointer in the
switch.
DW
- Next message: Dennis Handly: "Re: Template instantiation on HP aCC compiler"
- Previous message: Stephen Baynes.: "Re: Spell-checking source code"
- In reply to: Woodster: "Re: pointer to a method"
- Next in thread: Nirus: "Re: pointer to a method"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|