Accessing class member functions from Global Callback 
Author Message
 Accessing class member functions from Global Callback



Quote:
>One common method of dealing with things like this is to make your
>callback function a static member function of the class instead of
>being a global function.  ...

I like a different method - template function objects:
(I hope my syntax is correct here)

class Callback
{
    public:
        virtual int operator() ();

        Callback() {};

Quote:
}

template <class T, class ValType> class OneArgCallback:
public Callback
{
    public:
        typedef int (T::*)(ValType) FuncPtr;
        OneArgCallback(T *obj, FuncPtr f, ValType v)
                         :value(v), object(obj), func(f) { };

        virtual int operator() ()
                    {
                        object->*f(value);
                    };
    private:
        T *object;
        FuncPtr func;
        ValType value;

Quote:
}

And then set objects of this type as the callbacks, rather than
functions.


Sun, 06 Aug 2000 03:00:00 GMT  
 Accessing class member functions from Global Callback

[Copied to sender]

[snip]

Look, Stanley, I think your newsreader is seriously broken. It seems to
regularly misfire, and post messages surely intended for C++ newsgroups here
on comp.lang.c. Please fix this. Thanks.

--
(initiator of the grumpiness where grumpiness is due campaign in comp.lang.c)

Attempting to write in a hybrid which can be compiled by either a C compiler
or a C++ compiler produces a compromise language which combines the drawbacks
of both with the advantages of neither.



Sun, 06 Aug 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Passing C++ Class Member Function to as a C Callback Function Parameter

2. class member function as callback function

3. How to use member function of a C++ class as a callback function

4. access class's member in callback

5. CALLBACK Functions as Class Members

6. Making DDEML Callback function a member of a class

7. CALLBACK DLGPROC as a class member function

8. Making DDEML Callback function a member of a class

9. static function access member variable and member function

10. Getting pointer to non-static member function from C callback function

11. Callback functions as member functions

12. Calling C++ member function through C function callback

 

 
Powered by phpBB® Forum Software