首页 > 解决方案 > 变量或字段“...”在 Ardunio 编译器上声明为 void 错误

问题描述

我正在尝试编写飞行计算机。

关于这个错误的奇怪想法是:

此代码块完美运行:

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){

             ^~~~~~~~~~~

大家能帮我弄清楚这是为什么吗?

谢谢您,感谢您的所有意见

注意:这些代码是可重现的,您只需复制粘贴即可。

标签: c++arduino

解决方案


备查

我从另一个论坛得到了答案。问题在于 Arduino IDE 的自动原型生成。

这解决了问题。

void manuer(PlaneStatus ms);

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

推荐阅读