简体   繁体   English

关于类名的arduino c ++问题

[英]arduino c++ issues regarding class name

I am working on connecting my philips hue light bulbs to the arduino and found some resources online. 我正在将philips色调灯泡连接到arduino,并在网上找到了一些资源。 One of the resources has a file that keeps throwing an error and when I looked at it, I have never seen this syntax used before. 其中一个资源有一个文件,该文件不断抛出错误,当我查看它时,我从未见过使用过这种语法。 Can anyone help me out? 谁能帮我吗?

#ifndef SERIALHUE_H
#define SERIALHUE_H
#include <Arduino.h>
#include <Stream.h>
#include <ArduinoHue.h>



class SerialHue: public ArduinoHue{
 public:
SerialHue(char* ipAddress, Stream* serial);
boolean connect(char* deviceId, char* username);
 protected:
char* _ipAddress; 
char* _deviceId;
char* _username;
boolean makePost(char* request, char* data);
boolean waitForResponse();
Stream* _serial;
};

#endif

The error is in this line: 错误在这一行:

* class SerialHue: public ArduinoHue{ * * SerialHue类:公共ArduinoHue { *

Giving the error: 给出错误:

SerialHue.h:10: error: expected class-name before '{' token SerialHue.h:10:错误:“ {”令牌之前的预期类名

What is this format and what is wrong here? 这种格式是什么?这里有什么问题?

check the compiler settings...it might be possible that it tries to compile c++ code with ac compiler 检查编译器设置...它可能尝试使用ac编译器编译c ++代码

about the format: 关于格式:

class X : public Y {
}

is the syntax of extending a class in C++ 是在C ++中扩展类的语法

plus: check that ArduinoHue.h really defines ArduinoHue class 加:检查ArduinoHue.h是否确实定义了ArduinoHue类

...if you can't figure it out: take a look at the precompiled sourcefile (g++ -E) ...如果无法弄清楚:查看预编译的源文件(g ++ -E)

First, make sure that you are not recursively including a file, like #including a file that #includes other files you have also #included. 首先,请确保您没有递归地包含一个文件,例如#include一个文件,该文件#includes您也#included的其他文件。

Also, Forward declarations instead of #include ArduinoHue.h could solve your problem. 另外,转发声明而不是#include ArduinoHue.h可以解决您的问题。 such as: 如:

class ArduinoHue;

I have found similar questions, they might be able to help you: 我发现了类似的问题,它们也许可以为您提供帮助:
expected class-name before '{' token '{'令牌之前的预期类名

error: expected class-name before '{' token 错误:“ {”令牌之前的预期类名

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM