[英]Arduino Header file “No matching function for call to”
I've been working on an Arduino project. 我一直在从事Arduino项目。 Until recently I had everything in located in the one .ino file. 直到最近,我所有内容都位于一个.ino文件中。 I have decided to restructure my code and move my classes to their own files. 我已经决定重组我的代码并将我的类移到他们自己的文件中。
My problem is when I copy my Sensor class to a .h file, and include it, my program is unable to compile, and I get the following error. 我的问题是,当我将Sensor类复制到.h文件并包含它时,我的程序无法编译,并且出现以下错误。
If I copy it back to the .ino file, then everything works perfectly again. 如果我将其复制回.ino文件,则一切将再次正常运行。
In file included from GardenSensor.ino:1:0:
C:\Users\Brenton\AppData\Local\Temp\build5441194172372520295.tmp\Sensor.h: At global scope:
C:\Users\Brenton\AppData\Local\Temp\build5441194172372520295.tmp\Sensor.h:8:14: error: expected ')' before 'sensorType'
Sensor(byte sensorType, byte sensorID) : _sensorType(sensorType), _sensorID(sensorID) {}
^
C:\Users\Brenton\AppData\Local\Temp\build5441194172372520295.tmp\Sensor.h:14:2: error: 'byte' does not name a type
byte sensorID() { return _sensorID; }
^
C:\Users\Brenton\AppData\Local\Temp\build5441194172372520295.tmp\Sensor.h:15:2: error: 'byte' does not name a type
byte sensorType() { return _sensorType; }
^
C:\Users\Brenton\AppData\Local\Temp\build5441194172372520295.tmp\Sensor.h:18:2: error: 'byte' does not name a type
byte _sensorType;
^
C:\Users\Brenton\AppData\Local\Temp\build5441194172372520295.tmp\Sensor.h:19:2: error: 'byte' does not name a type
byte _sensorID;
^
GardenSensor.ino: In constructor 'AnalogSensor::AnalogSensor(byte, byte, byte)':
GardenSensor.ino:5:103: error: no matching function for call to 'Sensor::Sensor(byte&, byte&)'
GardenSensor.ino:5:103: note: candidates are:
In file included from GardenSensor.ino:1:0:
C:\Users\Brenton\AppData\Local\Temp\build5441194172372520295.tmp\Sensor.h:6:7: note: Sensor::Sensor()
class Sensor {
^
C:\Users\Brenton\AppData\Local\Temp\build5441194172372520295.tmp\Sensor.h:6:7: note: candidate expects 0 arguments, 2 provided
C:\Users\Brenton\AppData\Local\Temp\build5441194172372520295.tmp\Sensor.h:6:7: note: Sensor::Sensor(const Sensor&)
C:\Users\Brenton\AppData\Local\Temp\build5441194172372520295.tmp\Sensor.h:6:7: note: candidate expects 1 argument, 2 provided
GardenSensor.ino: In constructor 'SensorArray::SensorArray(unsigned int)':
GardenSensor.ino:16:35: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default]
GardenSensor.ino: In function 'void printAllSensors()':
GardenSensor.ino:61:29: error: 'class Sensor' has no member named 'sensorID'
GardenSensor.ino:66:30: error: 'class Sensor' has no member named 'sensorID'
no matching function for call to 'Sensor::Sensor(byte&, byte&)'
My Sensor class 我的传感器类
class Sensor {
public:
Sensor(byte sensorType, byte sensorID) : _sensorType(sensorType), _sensorID(sensorID) {}
virtual ~Sensor() {}
virtual unsigned int getReading() = 0;
byte sensorID() { return _sensorID; }
byte sensorType() { return _sensorType; }
private:
byte _sensorType;
byte _sensorID;
};
Thank you 谢谢
在您的外部代码文件中#include <Arduino.h>
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.