函数指针
C中 struct的函数实现,只能用函数指针成员
C/C code
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
#include
struct test
{
void fun()
{
printf("hello,world\n");
}
};
int main()
{
struct test _t;
_t.fun();
return...
C中 struct的函数实现,只能用函数指针成员
C/C code
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
#include
struct test
{
void fun()
{
printf("hello,world\n");
}
};
int main()
{
struct test _t;
_t.fun();
return 0;
}
上面的代码保存为.c, 在 VC 6.0, Dev Cpp 里都通不过。
函数指针方式实现,而不要直接定义函数 ...
当然 struct 里能放函数指针的。比如这样:
C/C code
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
#include
void fun()
{
printf("hello,world\n");
}
struct test
{
void (*Fun)();
};
int main()
{
struct test _t;
_t.Fun = fun;
(*_t.Fun)();
return 0;
}
C结构体内不能有函数的代码,但可以有函数的指针
网友回复:纯 C 中的 struct 没有成员函数,但可以有函数指针。
Object-oriented programming with ANSI-C是用函数指针来模拟成员函数的。
本文档为【函数指针】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑,
图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
该文档来自用户分享,如有侵权行为请发邮件ishare@vip.sina.com联系网站客服,我们会及时删除。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。
本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。
网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。