error C2440: “=”:无法从“int (__cdecl *)(void)”转换为“int (__cdecl *)(int,int)”

lanlinlalala 2018-07-18 09:31:32
#include <stdio.h>
#include <stdlib.h>


void main()
{
int max();
int (*pl)(int,int);
int a,b,c;
pl=max;
scanf("%d,%d",&a,&b);
c=(*pl)(a,b);
printf("a=%d,b=%d,max=%d",a,b,c);
system("pause");
}

int max(int x,int y)
{
int z;
if(x>y)
z=x;
else
z=y;
return z;
}

csdn1>d:\c++\新建文件夹\2\2\test_main.cpp(10): error C2440: “=”: 无法从“int (__cdecl *)(void)”转换为“int (__cdecl *)(int,int)”
程序为什么出现这种问题?望大佬解答一下
...全文
2866 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
huixionggege 2020-02-07
  • 打赏
  • 举报
回复 1
第一个 #include <stdlib.h> 内定义了MAX函数,在程序中用MAX(),会提示错误(),不过这个不是主要的问题。 主要问题在第二个,“int(*p)(int,int)”,2010vc里是类型转换问题,“int (__cdecl *)(void)”转换为“int (__cdecl *)(int,int)”计算机识别不了。 建议改一下: INT MAX(INT,INT); INT (*P)(INT,INT); 这可以解决报错的问题。
wang0635 2018-07-19
  • 打赏
  • 举报
回复
你看的书太老了,1980年前的C使用函数声明,只要声明其返回值类型就行了,参数不用说明;ansi c建议有函数原型,参数个数和类型必须说明
lanlinlalala 2018-07-19
  • 打赏
  • 举报
回复
这段程序是在以前的教材上找的,,,感谢各位了,,哈哈哈
lanlinlalala 2018-07-19
  • 打赏
  • 举报
回复
明白了,,,万分感谢
轻箬笠 2018-07-19
  • 打赏
  • 举报
回复
#include <stdio.h>
#include <stdlib.h>
int max(int x,int y);

void main()
{
int (*pl)(int,int);
int a,b,c;
pl=max;
scanf("%d,%d",&a,&b);
c=(*pl)(a,b);
printf("a=%d,b=%d,max=%d",a,b,c);
system("pause");
}

int max(int x,int y)
{
int z;
if(x>y)
z=x;
else
z=y;
return z;
}
仍在发呆的~ 2018-07-18
  • 打赏
  • 举报
回复
int max(); 你声明是无参
/*** *eh.h - User include file for exception handling. * * Copyright (c) 1993-1997, Microsoft Corporation. All rights reserved. * *Purpose: * User include file for exception handling. * * [Public] * ****/ #if _MSC_VER > 1000 #pragma once #endif #ifndef _INC_EH #define _INC_EH #if !defined(_WIN32) && !defined(_MAC) #error ERROR: Only Mac or Win32 targets supported! #endif #ifdef _MSC_VER // Currently, all MS C compilers for Win32 platforms default to 8 byte // alignment. #pragma pack(push,8) #endif // _MSC_VER #ifndef __cplusplus #error "eh.h is only for C++!" #endif /* Define _CRTIMP */ #ifndef _CRTIMP #ifdef _DLL #define _CRTIMP __declspec(dllimport) #else /* ndef _DLL */ #define _CRTIMP #endif /* _DLL */ #endif /* _CRTIMP */ /* Define _CRTAPI1 (for compatibility with the NT SDK) */ #ifndef _CRTAPI1 #if _MSC_VER >= 800 && _M_IX86 >= 300 #define _CRTAPI1 __cdecl #else #define _CRTAPI1 #endif #endif typedef void (__cdecl *terminate_function)(); typedef void (__cdecl *unexpected_function)(); typedef void (__cdecl *terminate_handler)(); typedef void (__cdecl *unexpected_handler)(); #ifndef _MAC struct _EXCEPTION_POINTERS; typedef void (__cdecl *_se_translator_function)(unsigned int, struct _EXCEPTION_POINTERS*); #endif #if _MSC_VER >= 1200 _CRTIMP __declspec(noreturn) void __cdecl terminate(void); _CRTIMP __declspec(noreturn) void __cdecl unexpected(void); #else _CRTIMP void __cdecl terminate(void); _CRTIMP void __cdecl unexpected(void); #endif _CRTIMP terminate_function __cdecl set_terminate(terminate_function); _CRTIMP unexpected_function __cdecl set_unexpected(unexpected_function); #ifndef _MAC _CRTIMP _se_translator_function __cdecl _set_se_translator(_se_translator_function); #endif #ifdef _MSC_VER #pragma pack(pop) #endif // _MSC_VER #endif // _INC_EH

70,038

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧