(注:这是纯C/ Arduino)。
我发现我的问题有很多联系,但没有人回答我。
我有一个文件"Effects.h“和"Keyboard.h”。
"Keyboard.h“需要包括"Effects.h”。所以"Effects.h“不能包括"Keyboard.h”
在"Effects.h“中,我实现了这三个函数:
extern fnKeyPress effectDrops();
extern fnKeyPress effectLineRotate();
extern fnKeyPress effectRainbowCycle();它们都应该返回一个指向接受这两个参数的函数的指针:const KeyWithColor *, const struct KeyConfiguration *
所以我想这么做:
typedef void (*fnKeyPress)(const KeyWithColor *, const struct KeyConfiguration *);
extern fnKeyPress effectDrops();
extern fnKeyPress effectLineRotate();
extern fnKeyPress effectRainbowCycle();但是不起作用,因为上面写着:
Effects.h:32: error: 'KeyWithColor' does not name a type
typedef void (*fnKeyPress)(const KeyWithColor *, const struct KeyConfiguration *);解决办法是什么?
发布于 2016-10-15 22:39:52
如果您需要转发声明KeyWithColor和(可能) KeyConfiguration:
(我不知道您的KeyWithColor类型是否是一个结构,我将假设它是为了简单起见)
然后放置这个:
struct KeyWithColor;
struct KeyConfiguration;在此之上:
typedef void (*fnKeyPress)(const KeyWithColor *, const struct KeyConfiguration *);
extern fnKeyPress effectDrops();
extern fnKeyPress effectLineRotate();
extern fnKeyPress effectRainbowCycle();这样做,您也是转发声明类型,如注释中所指出的。基本上告诉编译器:
你还不知道,但我保证它会被定义
小心不要把任何一种执行都放在前面的声明中。
https://stackoverflow.com/questions/40064731
复制相似问题