我已经写以下代码:C++ - 约函数指针问题
#include "stdafx.h"
#include <iostream>
using namespace std;
double funcA()
{
return 100.0;
}
int g(double (*pf)())
{
cout << (*pf)() << endl;
return 0;
}
int g2(double pf())
{
cout << pf() << endl;
return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
g(&funcA); // case I
g(funcA); // case II
g2(funcA); // case III
g2(&funcA); // case IV
return 0;
}
我已经运行上VS2008上面的代码,并且每个函数调用返回“100”。 这里是问题:
Q1>代码中是否有任何问题?
Q2>似乎C++在* pf和pf之间没有区别。那是对的吗?
谢谢
+1对于一个非常明确的问题。 – 2010-11-17 16:31:59
你也可以用g的声明和g2的body一起使用 – UncleZeiv 2010-11-17 16:33:55
我建议本教程关于函数指针:http://www.newty.de/fpt/index.html ..它非常全面 – Jack 2010-11-17 16:34:36