Arduino 头文件 "No matching function for call to"
Arduino Header file "No matching function for call to"
我一直在做一个 Arduino 项目。直到最近,我才将所有内容都放在一个 .ino 文件中。我决定重组我的代码并将我的 classes 移动到他们自己的文件中。
我的问题是当我将传感器 class 复制到 .h 文件并包含它时,我的程序无法编译,并且出现以下错误。
如果我将它复制回 .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&)'
我的传感器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;
};
谢谢
#include <Arduino.h>
在您的外部代码文件中。
我一直在做一个 Arduino 项目。直到最近,我才将所有内容都放在一个 .ino 文件中。我决定重组我的代码并将我的 classes 移动到他们自己的文件中。
我的问题是当我将传感器 class 复制到 .h 文件并包含它时,我的程序无法编译,并且出现以下错误。
如果我将它复制回 .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&)'
我的传感器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;
};
谢谢
#include <Arduino.h>
在您的外部代码文件中。