void main()
{
int max(int x,int y);
int a,b,c;
int (*p)();
p = max;
cin>>a>>b;
c = (*p)(a,b);
cout<<a<<" "<<b<<" "<<c<<" "<<endl;
}
int max(int x,int y)
{ int z;
if (x>y)
z = x;
else
z = y;
return z;
}
编译是的出错信息如下:
--------------------Configuration: Ptest - Win32 Debug--------------------
Compiling...
pt.cpp
D:\vc\Ptest\pt.cpp(67) : error C2440: '=' : cannot convert from 'int (__cdecl *)(int,int)' to 'int (__cdecl *)(void)'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
D:\vc\Ptest\pt.cpp(69) : error C2197: 'int (__cdecl *)(void)' : too many actual parameters
Error executing cl.exe.Ptest.exe - 2 error(s), 0 warning(s)
{
int max(int x,int y);
int a,b,c;
int (*p)();
p = max;
cin>>a>>b;
c = (*p)(a,b);
cout<<a<<" "<<b<<" "<<c<<" "<<endl;
}
int max(int x,int y)
{ int z;
if (x>y)
z = x;
else
z = y;
return z;
}
编译是的出错信息如下:
--------------------Configuration: Ptest - Win32 Debug--------------------
Compiling...
pt.cpp
D:\vc\Ptest\pt.cpp(67) : error C2440: '=' : cannot convert from 'int (__cdecl *)(int,int)' to 'int (__cdecl *)(void)'
This conversion requires a reinterpret_cast, a C-style cast or function-style cast
D:\vc\Ptest\pt.cpp(69) : error C2197: 'int (__cdecl *)(void)' : too many actual parameters
Error executing cl.exe.Ptest.exe - 2 error(s), 0 warning(s)
解决方案 »
- 客户端为什么没有调用CoFreeUnusedLibraries()?
- 调用rand()函数的问题:设置srand((unsigned int)time(0)),为什么还是全是一样的数?
- 为什么服务器接收连接函数CServerSocket::OnAccept(int nErrorCode)只响应第一个客户端?
- 怎么改变FormView 视图的背景色啊!
- 如何用VC写出使用Windows API调用约定的动态库函数?
- 如何将xml文件转换成access 数据库中的一个表
- 如何才能让我的CListCtrl类不想应鼠标的停靠,只响应鼠标的单击?
- 键盘钩子的问题
- HOOK问题,请大家帮忙看看^-^
- 程序在正常的简体操作系统上没有错误,在繁体操作系统上出现引数错误时为什么!求大神帮忙!
- 两个很很奇怪的小问题
- DLL调用紧急问题,高分求救!
{
int max(int x,int y);
int a,b,c;
int (*p)(int,int);
p = max;
cin>>a>>b;
c = (*p)(a,b);
cout<<a<<" "<<b<<" "<<c<<" "<<endl;
}
int max(int x,int y)
{ int z;
if (x>y)
z = x;
else
z = y;
return z;
}
谢谢!!!
但我还是不明白:
1,'int (__cdecl *)(int,int)' to 'int (__cdecl *)(void)'中的__cdecl是什么意思???
2,此外不是函数的说明只是对已经定义的函数的返回值进行类型说明(或称申明),它只包括函数名,函数类型,以及一个空的括号,不包括行参和函数体吗???