gpt4 book ai didi

c - 如何使用 typedef 定义结构

转载 作者:太空宇宙 更新时间:2023-11-04 06:39:16 24 4
gpt4 key购买 nike

我正在尝试执行以下操作:

typedef struct tagSTRUCT
{
MYPROC lpfnMyProc;
} STRUCT, *HSTRUCT;

typedef void (*MYPROC)(HSTRUCT);

void version1(HSTRUCT ); // version of delegate MYPROC
void version2(HSTRUCT ); // another version
...

,这给了我一个编译错误。我试图在 struct typedef 之前创建 'MYPROC' 的 typedef,但出现了编译错误。我尝试使用结构的前向声明,但也遇到了编译错误:

struct tagSTRUCT;
typedef tagSTRUCT STRUCT, *HSTRUCT;
typedef void (*MYPROC)(HSTRUCT );
struct tagSTRUCT
{
MYPROC lpfnMyProc;
};

我该怎么办?

最佳答案

试试这个:

struct tagSTRUCT;

typedef void (*MYPROC)(struct tagSTRUCT *);

typedef struct tagSTRUCT {
MYPROC p;
} STRUCT, * HSTRUCT;

关于c - 如何使用 typedef 定义结构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10803152/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com