图片链接 - /image/u9I3R.png
免除我的代码(省略一些,因为它们不重要)
struct viosReturnType {
bool done;
long long int returned;
bool remapped;
};
viosReturnType viosButtonprompt(char buf1[16], char buf2[16], bool keysp[6] = {0}, String *strar = 0, int *statear = 0) {...}
viosReturnType viosRemapreturn(viosReturnType lreturner, int *indexedarray){...}
viosButtonprompt
给我0麻烦,我的程序已经正常工作了一段时间。添加
viosRemapreturn
给我xxx/LVIOS.ino:585:1: error: 'viosReturnType' does not name a type
viosReturnType viosRemapreturn(viosReturnType lreturner, int *indexedarray){
^~~~~~~~~~~~~~
没有其他问题。函数内部的代码对这一切的影响为 0。参数对其中任何一个的影响为 0。图像显示所有这些都不存在于任何其他函数中,它们都是全局声明的,并且是相同的“viosReturnType”。这是什么东西,求求你帮忙。
我尝试将第二个函数放在第一个函数之上,没有效果,同样的错误,在同一个函数上,在不同的行。
另外:我现在尝试声明一个空函数,只是复制我的另一个函数声明的第一行。
viosReturnType viosRemapReturn(char buf1[16], char buf2[16], bool keysp[6] = {0}, String *strar = 0, int *statear = 0) {/*empty*/}
有用!成功!然后我删除了复制的参数。
viosReturnType viosReturnRemap(){/*still empty*/}
它抛出了同样的错误。我的心在爆炸。
代表:
int SmartPoint() {}
struct viosReturnType {
bool done;
long long int returned;
bool remapped;
};
viosReturnType returner;
viosReturnType viosRemapReturn(viosReturnType lreturner, int *indexedarray) {
if (lreturner.done)
return {1, indexedarray[lreturner.returned], 1};
}
void setup() {}
void loop() {}
你看到那个“SmartPoint”了吗?是的,如果我删除它,这个 reprex 会编译。但我不能真正在我的真实文件中的任何地方删除它,我没有任何类似的空函数或任何东西!
最佳答案
出于某种原因,Arduino 认为如果您定义了一个采用自定义数据类型的函数,那么自动生成函数原型(prototype)是一个好主意。我认为他们这样做是为了“易于使用”,所以您不必担心前向声明?当该函数使用自定义数据类型时,这会导致问题(如您所见)。然后将该原型(prototype)放在自定义数据类型定义之前,这会使编译器感到困惑。
为了克服这种自动原型(prototype)创建,您需要在声明数据类型之后显式声明函数原型(prototype)。像这样
int SmartPoint() {}
struct viosReturnType {
bool done;
long long int returned;
bool remapped;
};
viosReturnType returner;
// this prototype is to suppress arduino automatic prototype construction
// above viosReturnType definition
viosReturnType viosRemapReturn(viosReturnType lreturner, int *indexedarray);
viosReturnType viosRemapReturn(viosReturnType lreturner, int *indexedarray) {
if (lreturner.done)
return {1, indexedarray[lreturner.returned], 1};
}
void setup() {}
void loop() {}
另一种解决方案是将结构定义放在单独的
.h
中。文件,并将其包含在您的主文件中,以便在包含后包含原型(prototype)。// vios_return_type.h
#ifndef VIOS_RETURN_TYPE_H
#define VIOS_RETURN_TYPE_H
struct viosReturnType {
bool done;
long long int returned;
bool remapped;
};
#endif // VIOS_RETURN_TYPE_H
#include "vios_return_type.h"
int SmartPoint() {}
viosReturnType returner;
viosReturnType viosRemapReturn(viosReturnType lreturner, int *indexedarray) {
if (lreturner.done)
return {1, indexedarray[lreturner.returned], 1};
}
void setup() {}
void loop() {}
关于c++ - Arduino编译错误: xxx does not name a type (despite it being declared 10 lines before),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60937729/