我的代碼有問題。C + + - 錯誤:沒有匹配函數調用'Motor :: Motor()'
我有兩個錯誤:
拳錯誤:
MotorManager.cpp:7: error: no matching function for call to 'Motor::Motor()'
二錯誤:
MotorManager.cpp:10: error: use of deleted function 'Motor& Motor::operator=(Motor&&)'
MotorManager.cpp
#include "MotorManager.h"
#include "Pins.h"
#include "Direction.h"
#include "Motor.h"
MotorManager::MotorManager() {
// Init motors
_motorLeftFront = Motor(MOTOR_FRONT_LEFT_FORWARD, MOTOR_FRONT_LEFT_BACKWARD);
_motorRightFront = Motor(MOTOR_FRONT_RIGHT_FORWARD, MOTOR_FRONT_RIGHT_BACKWARD);
_motorLeftBack = Motor(MOTOR_BACK_LEFT_FORWARD, MOTOR_BACK_LEFT_BACKWARD);
_motorRightBack = Motor(MOTOR_BACK_RIGHT_FORWARD, MOTOR_BACK_RIGHT_BACKWARD);
}
MotorManager.h
#include "Pins.h"
#include "Direction.h"
#include "Motor.h"
class MotorManager {
public:
// Constuctor
MotorManager();
};
Motor.cpp
#include "Motor.h"
#include "Direction.h"
Motor::Motor(const int pinForwad, const int pinBackward) : _pinForwad(pinForwad), _pinBackward(pinBackward) {
pinMode(pinForwad, OUTPUT);
pinMode(pinBackward, OUTPUT);
}
Motor.h
#include "Direction.h"
class Motor {
public:
// Constructor
Motor(const int pinForwad, const int pinBackward);
private:
//Variables
int _pinForwad;
int _pinBackward;
};
由於
'類Motor'不提供默認的構造函數,併爲您指定你自己的,編譯器不會生成一個給你。 –