参考:rel=“nofollow”> [33.11] Can 页: 1
#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;
}
Question> Which way, the original or updated, is the recommended method? I have tested both methods with VS2010 and each prints the correct result.
谢谢。
Although I do see the following usage in the original post:
void baz()
{
FredMemFn p = &Fred::f; ← declare a member-function pointer
...
}