变量或字段“...”在 Ardunio 编译器上声明为无效错误
Variable or field '...' declared void Error on Ardunio Compiler
我正在尝试编写飞行计算机代码。
这个错误的奇思妙想是:
此代码块完美运行:
class PlaneStatus {
public:
PlaneStatus(double y, double p, double r, double t) {
yaw = y;
pitch = p;
roll = r;
throttle = t;
}// Access specifier
double yaw, pitch, roll, throttle; // Attribute (int variable)
};
void manuer(PlaneStatus ms){
ms.pitch;
}
void setup(){}
void loop(){}
但是当我添加另一个与该对象完全无关的函数时,会出现有关 PlaneStatus 对象的错误。
#include <Servo.h>
#include <Wire.h>
void driveServo(Servo servo, int trin ,int arg){
servo.write(trin+ arg);
}
class PlaneStatus {
public:
PlaneStatus(double y, double p, double r, double t) {
yaw = y;
pitch = p;
roll = r;
throttle = t;
}// Access specifier
double yaw, pitch, roll, throttle; // Attribute (int variable)
};
void manuer(PlaneStatus ms){
ms.pitch;
}
void setup(){}
void loop(){}
这是错误信息
sketch_jul01a:67:13: error: variable or field 'manuer' declared void
void manuer(PlaneStatus ms){
^~~~~~~~~~~
sketch_jul01a:67:13: error: 'PlaneStatus' was not declared in this scope
C:\Users\isatu\AppData\Local\Temp\arduino_modified_sketch_56794\sketch_jul01a.ino:67:13: note: suggested alternative: 'mpuIntStatus'
void manuer(PlaneStatus ms){
^~~~~~~~~~~
你们能帮我看看这是为什么吗?
谢谢您,感谢所有意见
注意:这些代码是可复制的,您只需复制粘贴即可。
供日后参考
我从另一个论坛得到了答案。问题出在 Arduino IDE 的自动原型生成上。
这解决了问题。
void manuer(PlaneStatus ms);
void manuer(PlaneStatus ms) {
ms.pitch;
}
我正在尝试编写飞行计算机代码。
这个错误的奇思妙想是:
此代码块完美运行:
class PlaneStatus {
public:
PlaneStatus(double y, double p, double r, double t) {
yaw = y;
pitch = p;
roll = r;
throttle = t;
}// Access specifier
double yaw, pitch, roll, throttle; // Attribute (int variable)
};
void manuer(PlaneStatus ms){
ms.pitch;
}
void setup(){}
void loop(){}
但是当我添加另一个与该对象完全无关的函数时,会出现有关 PlaneStatus 对象的错误。
#include <Servo.h>
#include <Wire.h>
void driveServo(Servo servo, int trin ,int arg){
servo.write(trin+ arg);
}
class PlaneStatus {
public:
PlaneStatus(double y, double p, double r, double t) {
yaw = y;
pitch = p;
roll = r;
throttle = t;
}// Access specifier
double yaw, pitch, roll, throttle; // Attribute (int variable)
};
void manuer(PlaneStatus ms){
ms.pitch;
}
void setup(){}
void loop(){}
这是错误信息
sketch_jul01a:67:13: error: variable or field 'manuer' declared void
void manuer(PlaneStatus ms){
^~~~~~~~~~~
sketch_jul01a:67:13: error: 'PlaneStatus' was not declared in this scope
C:\Users\isatu\AppData\Local\Temp\arduino_modified_sketch_56794\sketch_jul01a.ino:67:13: note: suggested alternative: 'mpuIntStatus'
void manuer(PlaneStatus ms){
^~~~~~~~~~~
你们能帮我看看这是为什么吗?
谢谢您,感谢所有意见
注意:这些代码是可复制的,您只需复制粘贴即可。
供日后参考
我从另一个论坛得到了答案。问题出在 Arduino IDE 的自动原型生成上。
这解决了问题。
void manuer(PlaneStatus ms);
void manuer(PlaneStatus ms) {
ms.pitch;
}