c++ - 变量或字段“...”在 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){
^~~~~~~~~~~
大家能帮我弄清楚这是为什么吗?
谢谢您,感谢您的所有意见
注意:这些代码是可重现的,您只需复制粘贴即可。
解决方案
备查
我从另一个论坛得到了答案。问题在于 Arduino IDE 的自动原型生成。
这解决了问题。
void manuer(PlaneStatus ms);
void manuer(PlaneStatus ms) {
ms.pitch;
}
推荐阅读
- multer - Node.js multer:不能两次上传相同的文件
- arrays - EXPECTED BEGIN_ARRAY 但在第 1 行第 2 列 PATH $22 处出现 BEGIN_OBJECT
- javascript - 如何检查列表是否存在于java脚本中的其他数组列表中,没有循环
- javascript - 为什么我的 JavaScript 计算器不工作?
- flutter - 如何为使用 Custom Painter 绘制的形状添加渐变?
- android - 可以获取其他应用的audioStream吗
- css - CSS 对除图像之外的所有内容使用填充
- javascript - 当服务器正在处理视图时,如何在 Django 中显示加载动画?
- c# - 如何在 C# 中解决这个 SqlConnection?
- javascript - 使用无密码身份验证删除用户帐户?