简体   繁体   English

用函数指针构造

[英]Struct with pointer to a function

In a C struct I have defined a function pointer as follows: 在C结构中,我定义了一个函数指针,如下所示:

typedef struct _sequence_t
{
  const int seq[3];
  typedef void (* callbackPtr)();
} sequence_t;

I want to initialize a var of that type globally with: 我想用以下方法全局初始化该类型的var:

sequence_t sequences[] = {
  { { 0, 1, 2 }, toggleArmament },
};

And I keep getting error telling me that there are too many initializers. 而且我不断收到错误消息,告诉我初始化器太多。 How to work it out? 如何解决?

typedef is used to declare an alias to a type. typedef用于声明类型的别名。 Since you have an actual member here, remove the inner typedef . 由于您在此处拥有实际成员,因此请删除内部的typedef

typedef struct _sequence_t
{
  const int seq[3];
  void (* callbackPtr)();
} sequence_t;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM