我是 C++ 新手。这是我的问题。我在 h 文件中将总线、步进器声明为私有实例:
class Motor_control
{
public:
...
private:
IICBus bus ;
IICStepper stepper ;
IICStepper stepper_r ;
IICStepper stepper_l ;
};
然后在构造函数中初始化它们
Motor_control::Motor_control(){
IICBus bus ("/dev/i2c-2",0,"");
IICStepper stepper (bus,0x00, "Global addr");
IICStepper stepper_r (bus,0x6e, "Stepper Modul");
IICStepper stepper_l (bus,0x66, "Stepper Modul");
}
IICStepper 在 .cpp 中声明:
IICStepper::IICStepper(IICBus& bus, int addr, const string& name) : IICBase(bus,addr, name) { } in cpp
在.h中:
class IICStepper : public IICBase { public: IICStepper(IICBus& bus, int addr, const std::string& name); virtual ~IICStepper(){}; ...}
它比较
../src/Motor_control.h:15: error: no matching function for call to 'IICStepper::IICStepper()'
../src/Stepper.h:41: note: candidates are: IICStepper::IICStepper(IICBus&, int, const std::string&)
../src/Stepper.h:38: note: IICStepper::IICStepper(const IICStepper&)
../src/Motor_control.h:15: error: no matching function for call to 'IICBus::IICBus()'
../src/Bus.h:28: note: candidates are: IICBus::IICBus(const std::string&, int, const std::string&)
../src/Bus.h:17: note: IICBus::IICBus(const IICBus&)
../src/Motor_control.h:15: error: no matching function for call to 'IICStepper::IICStepper()'
../src/Stepper.h:41: note: candidates are: IICStepper::IICStepper(IICBus&, int, const std::string&)
../src/Stepper.h:38: note: IICStepper::IICStepper(const IICStepper&)
../src/Motor_control.h:15: error: no matching function for call to 'IICStepper::IICStepper()'
../src/Stepper.h:41: note: candidates are: IICStepper::IICStepper(IICBus&, int, const std::string&)
../src/Stepper.h:38: note: IICStepper::IICStepper(const IICStepper&)
../src/Motor_control.h:15: error: no matching function for call to 'IICStepper::IICStepper()'
../src/Stepper.h:41: note: candidates are: IICStepper::IICStepper(IICBus&, int, const std::string&)
../src/Stepper.h:38: note: IICStepper::IICStepper(const IICStepper&)