• Welcome to Valhalla Legends Archive.
 

Pointers to Member Functions

Started by MyndFyre, October 12, 2004, 07:56 AM

Previous topic - Next topic

MyndFyre

Let's say I have the class definition:


class MyType
{
    public:
      doSomething(int nNumber, char *szText);
}


I want to create the typedef to have a pointer to that function.  However, that function requires use of the this pointer.  Where is the this pointer situated, and does it depend on the calling convention?


typedef (* pDoSomethingFunc)(int, char*, MyType*) PDSFUNC;
typedef (* pDoSomethingFunc)(MyType*, int, char*) PDSFUNC;


Or is it something else?
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

K

AFAIK you can't really have a pointer to a non-static member function; the compiler won't let you.   If you want to try to hack it, though, member functions using thiscall pass the pointer in ecx and member functions using the c calling convention (which you really only need on member functions if you want to use varargs) pass it as an extra parameter.

Yoni


class MyType
{
    public:
        int doSomething(int nNumber, char *szText);
};

typedef int (MyType::* PDSFUNC)(int, char*);

...

MyType* bleh;
PDSFUNC p;
int a;
char* b;

...

(bleh->*p)(a, b);

I keep this in Misc.txt because it's hard to remember. Enjoy. :)

MyndFyre

QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.