c++ - 变量或字段 '...' 在 Arduino 编译器上声明为 void 错误

标签 c++ arduino

我正在尝试编写飞行计算机。
关于这个错误的奇怪想法是:
此代码块完美运行:

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 的自动原型(prototype)生成。
这解决了问题。

void manuer(PlaneStatus ms);

void manuer(PlaneStatus ms) {
  ms.pitch;
}

关于c++ - 变量或字段 '...' 在 Arduino 编译器上声明为 void 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62683653/

相关文章:

c++ - 为什么整数上的 std::hex 和 void* 会产生相同的值

c++ - 而无限循环?

header - 为 Arduino 以太网上传出的 UDP 数据报设置 IP 数据包的生存时间 (TTL)

c++ - 什么是初始化的子表达式

c++ - Taylor McLaughlin 级数估计两点的距离

c - pgm_read_ 和 PROGMEM - 意外行为

java - 将所有端口列为 JComboBox

c++ - 为什么 Arduino Micro(USB 设备)的供应商 ID 和产品 ID 在 Linux 和 Windows 中不同?

Arduino 的 Java 记录器

c++ - 如何枚举最小值和最大值之间的所有浮点值