By default you can only make a pointer to a function, like in C:
PHP Code:
typedef float (*MyFuncPtrType)(int, char *);
MyFuncPtrType my_func_ptr = some_func;
// call it like some_func(7, "Arbitrary String");
(*my_func_ptr)(7, "Arbitrary String");
Borland C++ Builder allowed me to also use any class in there using
__closure, but now that I moved to ISO C++ this is not available anymore unless i explicity name the class inside the typedef like:
PHP Code:
typedef float (SomeClass::*my_memfunc_ptr)(int, char *);
After some googling i found several solutions to this problem in toolkits like
Boost but also in some documentations.
The bug exists still as of today although several compilers have a solution and others live with the bug for over 15 years now, since the original author already pointed a solution more then 15 years ago.
But now you want to know "what is the solution?". Well i can tell you that in one simple line:
http://www.codeproject.com/cpp/FastDelegate.asp
I found this nifty pack after reading many google results and it seems to comply with most common used compilers.
C++ will now even more rock your world
How i use this functor? Well some functions need to be private or protected BUT have to be called thru a Windows procedure like the ThreadProc or WindowProc.
Why? Well simple, Windows procedures are C so they can't deal with C++ nor does the X system.
A good example is multi-threaded applications, each new thread calls a procedure to run inside the thread. In my case this is inside a class and the class function that starts it is "run()" and is protected so that you can't run the class outside the thread (talking fail-safe or application locking prevention here)
I will post my Thread class for Windows/X when i get them properly working as i want it including synchronization
