我有两个基本的Cpp任务,但我仍然遇到问题。首先编写函数mul1,div1,sub1,sum1,将int作为参数并返回int。然后,我需要创建函数mul1和sum1的指针ptrFun1和ptrFun2,并打印使用它们的结果。问题从定义这些指针开始。我以为我做得对,但devcpp给我编译错误。函数指针
#include <iostream>
using namespace std;
int mul1(int a,int b)
{
return a * b;
}
int div1(int a,int b)
{
return a/b;
}
int sum1(int a,int b)
{
return a + b;
}
int sub1(int a,int b)
{
return a - b;
}
int main()
{
int a=1;
int b=5;
cout << mul1(a,b) << endl;
cout << div1(a,b) << endl;
cout << sum1(a,b) << endl;
cout << sub1(a,b) << endl;
int *funPtr1(int, int);
int *funPtr2(int, int);
funPtr1 = sum1;
funPtr2 = mul1;
cout << funPtr1(a,b) << endl;
cout << funPtr2(a,b) << endl;
system("PAUSE");
return 0;
}
38 assignment of function `int* funPtr1(int, int)' 38 cannot convert `int()(int, int)' to `int*()(int, int)' in assignment
任务2是创建指向那些命名tabFunPtr功能的阵列。怎么做 ?
Dev-Cpp是旧的和无人维护的。 你应该尝试Code :: Blocks。 http://www.codeblocks.org/ – 2010-04-26 19:16:42
DevC++是一个古老的垃圾桶。你需要一个更新的编译器。 – Puppy 2012-10-01 13:33:41