结构体能否有函数成员

来源:互联网 发布:linux java安装 编辑:程序博客网 时间:2024/05/02 14:21
#include <stdio.h>
typedef struct CStructure
{
int (*memberFunction)();
}CStructure;
int globalFunction()
{
printf("Member function of a struct in C\n");
return 0;
}
int main()
{
CStructure obj;
obj.memberFunction=globalFunction;
obj.memberFunction();
return 0;
}

说这个不是函数成员,,而是函数指针
因此,C的结构体不能包含真正的成员函数这是毫无疑问的。

看来问题清楚了.
0 0
原创粉丝点击