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.