#include <stdio.h>
struct context;
struct funcptrs{
void (*func0)(context *ctx);
void (*func1)(void);
};
struct context{
funcptrs fps;
};
void func1 (void) { printf( "1\n" ); }
void func0 (context *ctx) { printf( "0\n" ); }
void getContext(context *con){
con=?; // please fill this with a dummy example so that I can get this working. Thanks.
}
int main(int argc, char *argv[]){
funcptrs funcs = { func0, func1 };
context *c;
getContext(c);
c->fps.func0(c);
getchar();
return 0;
}
我在这里缺少一些东西。如何解决这个问题?
结构体(没有 typedef)在使用时通常需要(或应该)带有关键字 struct。
struct A; // forward declaration
void function( struct A *a ); // using the 'incomplete' type only as pointer
如果您输入结构体,则可以省略 struct 关键字。
typedef struct A A; // forward declaration *and* typedef
void function( A *a );
请注意,重用结构名称是合法的
尝试在代码中将前向声明更改为:
typedef struct context context;
添加后缀来指示结构名称和类型名称可能更具可读性:
typedef struct context_s context_t;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)