The return type for the pointer to member function is void. I want to reassign to the function pointer a new function within the SomeClass class with a different type (USHORT).
How do I do this? I realize there may be altogether better ways to write it, but...
I tried dynamic cast...but I didn't work so well.
want to point to &SomeClass::anotherfx instead....of ptr_fx = & SomeClass::somefx
...
typedefunsignedshortint USHORT;
class SomeClass
{
public:
virtualvoid somefx(USHORT a, USHORT b) { cout<<"a * b = "<<a*b<<"\n"; };
USHORT anotherfx(USHORT a){ cout<<"test\n";};
...
void (SomeClass::*fx_ptr) (USHORT, USHORT)
...
int _tmain(int argc, _TCHAR* argv[])
{
//declare pointer to class fx
void (SomeClass::*fx_ptr) (USHORT, USHORT);
fx_ptr = &SomeClass::somefx;
SomeClass * class_ptr = new SomeClass;
(class_ptr->*fx_ptr)(3,4);
//let's declare pointer to class fx with a typedef instead
typedefvoid(SomeClass::*VPF)(USHORT, USHORT); // this can go above main under class dec if wants
//let's set this function pointer to address of the function itself
VPF ptr_fx = &SomeClass::somefx;
//guess what - below - we can still use the original object we created with the new pointer
(class_ptr->*ptr_fx)(5,5);
system("PAUSE");
// reassign pointer to a fx of diff type
ptr_fx = &SomeClass::anotherfx; //ERROR
You can't. That's like saying "Why can't I change my class that contains an int into a class that contains a string?" They are completely different types.