C中struct的函数实现,只能用函数指针成员。
C结构体内不能有函数的代码,但可以有函数的指针。
C/C code
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
#include <stdio.h>
struct test
{
};
int main()
{
}
上面的代码保存为.c, 在VC 6.0, Dev Cpp 里都通不过。
函数指针方式实现,而不要直接定义函数 ...
当然struct里能放函数指针的。比如这样:
C/C code
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
#include <stdio.h>
void fun()
{
}
struct test
{
};
int main()
{
}
C结构体内不能有函数的代码,但可以有函数的指针
网友回复:纯C中的struct没有成员函数,但可以有函数指针。
Object-oriented programming with ANSI-C是用函数指针来模拟成员函数的。
参考:http://blog.sina.com.cn/s/blog_502d82e10100fgl1.html
最后
以上就是刻苦大门最近收集整理的关于C中struct的函数的实现的全部内容,更多相关C中struct内容请搜索靠谱客的其他文章。
发表评论 取消回复