指针问题(用VC++6.0),请问如何解决
#include<stdio.h>intf1(intx){returnx+1;}intf2(intx){returnx-1;}intsum_square(int(*f)(...
#include <stdio.h>
int f1(int x)
{return x+1;
}
int f2(int x)
{return x-1;
}
int sum_square(int (*f)(),int m,int n)
{int k,sum=0;
for(k=m;k<=n;k++)
sum+=(*f)(k)*(*f)(k);
return sum;
}
void main()
{printf("result=%d\n",sum_square(f1,1,2)+sum_square(f2,1,2));
}
--------------------Configuration: 811 - Win32 Debug--------------------
Compiling...
811.cpp
D:\Microsoft+Visual C++6.0简体中文企业版\C语言\811.cpp(11) : error C2197: 'int (__cdecl *)(void)' : too many actual parameters
D:\Microsoft+Visual C++6.0简体中文企业版\C语言\811.cpp(11) : error C2197: 'int (__cdecl *)(void)' : too many actual parameters
D:\Microsoft+Visual C++6.0简体中文企业版\C语言\811.cpp(15) : error C2664: 'sum_square' : cannot convert parameter 1 from 'int (int)' to 'int (__cdecl *)(void)'
None of the functions with this name in scope match the target type
D:\Microsoft+Visual C++6.0简体中文企业版\C语言\811.cpp(15) : error C2664: 'sum_square' : cannot convert parameter 1 from 'int (int)' to 'int (__cdecl *)(void)'
None of the functions with this name in scope match the target type
执行 cl.exe 时出错.
811.obj - 1 error(s), 0 warning(s) 展开
int f1(int x)
{return x+1;
}
int f2(int x)
{return x-1;
}
int sum_square(int (*f)(),int m,int n)
{int k,sum=0;
for(k=m;k<=n;k++)
sum+=(*f)(k)*(*f)(k);
return sum;
}
void main()
{printf("result=%d\n",sum_square(f1,1,2)+sum_square(f2,1,2));
}
--------------------Configuration: 811 - Win32 Debug--------------------
Compiling...
811.cpp
D:\Microsoft+Visual C++6.0简体中文企业版\C语言\811.cpp(11) : error C2197: 'int (__cdecl *)(void)' : too many actual parameters
D:\Microsoft+Visual C++6.0简体中文企业版\C语言\811.cpp(11) : error C2197: 'int (__cdecl *)(void)' : too many actual parameters
D:\Microsoft+Visual C++6.0简体中文企业版\C语言\811.cpp(15) : error C2664: 'sum_square' : cannot convert parameter 1 from 'int (int)' to 'int (__cdecl *)(void)'
None of the functions with this name in scope match the target type
D:\Microsoft+Visual C++6.0简体中文企业版\C语言\811.cpp(15) : error C2664: 'sum_square' : cannot convert parameter 1 from 'int (int)' to 'int (__cdecl *)(void)'
None of the functions with this name in scope match the target type
执行 cl.exe 时出错.
811.obj - 1 error(s), 0 warning(s) 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询