# [Win32-dev] info on pointer to member function...

Bret McMillan brm@acpub.duke.edu
Tue, 2 Nov 1999 12:24:14 -0500

- Previous message: [Win32-dev] info on pointer to member function...
- Next message: [Win32-dev] info on pointer to member function...
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

    >   The best way I found to do it would be to basically have a static
    function
    > that would take as a parameter the object, which would then be stored as
    one of
    > the parameters to pass the callback.  When the callback is then recieved,
    one
    > would simply have the funciton call the given member function of the
    object
    > passed.

    Here's something from good ol' Bjarne:

    Consider the following class:

    class Std_interface {
    public:
    ...
      virtual void suspend() = 0;
    ...
      virtual ~Std_interface() {}
    };

    To invoke suspend() without calling it directly, consider this example:

    typedef void (Std_interface:: * Pstd_mem) ();   // pointer to member type...
    /*
    Note that this is for a void function that takes no parameters.  For one w/
    parameters, I'm pretty sure you just put them in the ()'s at the end...
    */

    void f(Std_interface* p)
    {
        Pstd_mem s = &Std_interface::suspend;

        // direct call...
        p->suspend();

        // call through pointer to member...
        (p->*s)();
    }

    God I love C++.  <g>

    Bret

- Previous message: [Win32-dev] info on pointer to member function...
- Next message: [Win32-dev] info on pointer to member function...
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]