Should we use p(..) or (*p)(..) when p is a function pointer?
- by q0987
Reference: [33.11] Can I convert a pointer-to-function to a 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;
}
Question Which way, the original or updated, is the recommended method?
Thank you
Although I do see the following usage in the original post:
void baz()
{
FredMemFn p = &Fred::f; ? declare a member-function pointer
...
}