一个百思不得其解的c编程问题,高手请进!!!!

来源:百度知道 编辑:UC知道 时间:2024/05/15 15:57:19
#include<stdio.h>
int max(int a,int b)
{
if(a>b)
return a;
else
return b;
}
void main()
{
int max(int a,int b);
int (*pmax)();
int x,y,z;
pmax=max;
printf("input two numbers:\n");
scanf("%d%d",&x,&y);
z=(*pmax)(x,y);
printf("maxnum=%d",z);
}
这段程序在vc6中无法通过,出错信息是
--------------------Configuration: lianxi62 - Win32 Debug--------------------
Compiling...
lianxi62.cpp
D:\vc\MSDev98\MyProjects\lianxi62\lianxi62.cpp(14) : 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\MSDev98\MyProjects\lianxi62\lianxi62.cpp(17) : error C2197: 'int (__cdecl *)(void)' : too many actual parameters
执行 cl.exe 时出

指向函数的指针在C中允许这样做,但C++不允许的
C++要求编译器编译阶段就检查,尽一切可能保证如此危险的函数指针的安全性。如果你用的vc肯定就通不过了

我试了一下,也不知道怎么改。指向函数的指针以前老师就叫我们放弃,因为很少用到。

直接在用命令行用cl lianxi.c