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)

解决方案 »

  1.   

    void main()
    {
    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;
    }
      

  2.   

    老大,为何int (*p)(int,int);要加)(int,int)?
    谢谢!!!
      

  3.   

    老大,谢谢你的信息,
    但我还是不明白:
    1,'int (__cdecl *)(int,int)' to 'int (__cdecl *)(void)'中的__cdecl是什么意思???
    2,此外不是函数的说明只是对已经定义的函数的返回值进行类型说明(或称申明),它只包括函数名,函数类型,以及一个空的括号,不包括行参和函数体吗???