Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Be grateful for Perl OO

by John M. Dlugosz (Monsignor)
on Jan 28, 2003 at 17:26 UTC ( [id://230658]=note: print w/replies, xml ) Need Help??


in reply to Be grateful for Perl OO

Class_A and Class_B share an interface, but not a base class

If you can't factor out the interface as a base class because you're not allowed to touch the code, just use a template.

Since all the functions have the same signature (that is, no parameters) you can use pointers to member functions in C++.

Replies are listed 'Best First'.
Re: Re: Be grateful for Perl OO
by tall_man (Parson) on Jan 28, 2003 at 18:09 UTC
    Yes, functors created using templates would help a lot. See Modern C++ Design for some amazing things you can do with C++ templates.

    Update: The basic idea is using a templated function like this:

    template <class Type> double doCall(Type *instance, double (Type::*pmf)()) { return (instance->*pmf)(); }
    Update 1/19/03: Transposed the return type to the proper place in the declaration. Thanks to John M. Dlugosz.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://230658]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-19 07:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found