Link: [33.11] Is it possible to convert a pointer to a function in void *?
#include "stdafx.h" #include <iostream> int f(char x, int y) { return x; } int g(char x, int y) { return y; } typedef int(*FunctPtr)(char,int); int callit(FunctPtr p, char x, int y) // original { return p(x, y); } int callitB(FunctPtr p, char x, int y) // updated { return (*p)(x, y); } int _tmain(int argc, _TCHAR* argv[]) { FunctPtr p = g; // original std::cout << p('c', 'a') << std::endl; FunctPtr pB = &g; // updated std::cout << (*pB)('c', 'a') << std::endl; return 0; }
Questions> Which method, original or updated, is the recommended method? I tested both methods with VS2010 and each prints the correct result.
thanks
Although in the original post I see the following usage:
void baz() { FredMemFn p = &Fred::f; ← declare a member-function pointer ... }
q0987 source share