函数指针声明时的形参列表可以没有

在VC6.0环境中调试程序时遇到errorC2440错误,通过修改函数指针定义方式成功解决问题。具体操作包括:将PFpfun=add;修正为PFpfun=(void(__cdecl*)(int,int,...))add;,并实现了一个简单的add函数,用于演示如何正确定义和使用函数指针。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原文地址:http://www.cnblogs.com/mlj318/archive/2011/11/02/2233106.html

在VC 6.0 环境中调试程序出现错误

error C2440: 'initializing' : cannot convert from '' to 'void (__cdecl *)(int,int,...)'
        None of the functions with this name in scope match the target type
将PF pfun = add; 修正为 PF pfun = (void (__cdecl *)(int,int,...))add;

修正结果为下面代码中显示:

#include <stdio.h>
#include <stdlib.h>

typedef void (* PF)(int,int,...);

void add(int a,int b,int *result)
{
   *result=a+b;
   printf("result:%d\n",*result);
}

void main()
{
	int x,y,z;

	PF pfun = (void (__cdecl *)(int,int,...))add;
	x=5;
	y=4;	
	pfun(x,y,&z);
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值