Valhalla Legends Forums Archive | C/C++ Programming | Pointers to Member Functions

AuthorMessageTime
Myndfyr
Let's say I have the class definition:

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

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?

[code]
typedef (* pDoSomethingFunc)(int, char*, MyType*) PDSFUNC;
typedef (* pDoSomethingFunc)(MyType*, int, char*) PDSFUNC;
[/code]

Or is it something else?
October 12, 2004, 12:56 PM
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.
October 12, 2004, 9:23 PM
Yoni
[code]
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);
[/code]
I keep this in Misc.txt because it's hard to remember. Enjoy. :)
October 12, 2004, 9:28 PM
Myndfyr
Thanks Yoni!
October 12, 2004, 10:42 PM

Search