void DummyFunction() {}typedef void (*TFunctionPointer)();typedef void (&TFunctionReference)();int main() { TFunctionPointer fp1 = DummyFunction; TFunctionPointer fp2 = &DummyFunction; TFunctionReference fr1 = DummyFunction; TFunctionReference fr2 = *DummyFunction; fp1(); fp2(); fr1(); (&fr1)(); fr2(); return 0; }
You can see that you don't need the &-operator to get a function pointer. The C++ Programming Language says:.
Quote:The C++ Programming Language, 7.7 Pointer to Function
... That is, dereferencing of a pointer to function using * is optional. Similarly, using & to get the address of a function is optional...
Now I want to do the same thing for pointers to methods. Unfortunately, a 'reference to method' doesn't seem to be possible. The following code doesn't compile:
struct DummyStruct { void DummyMethod() {} };typedef void (DummyStruct::*TMethodPointer)(); //oktypedef void (DummyStruct::&TMethodReference)(); //error
There is nothing that cannot be done with method pointers, but it would be nice to be able to have a method reference as parameter (for the same reason it's nice to be able to use normal references instead of pointers). Anybody any clue whether this is possible? Thanks!