我正在尝试创建一个名为的对象,名为。该对象由温度计对象,内存对象,LED对象。最后三节课完全分开。但是,当我尝试在照明类中粘贴所有内容时,我得到以下消息:对象组合C++:没有用于调用的匹配函数
luminary.cpp:11:112:错误:没有匹配函数调用'Thermometer :: Thermometer()' luminary.cpp: 11:112:错误:没有匹配函数调用'Memory :: Memory()'
luminary.cpp:11:112:错误:没有匹配函数调用'Led :: Led()'
规范灯具类的头文件:
class Luminary{
public:
//Constructor
Luminary(Led led,Thermometer thermometer,Memory memory);
//Atributes
Led _led;
Thermometer _thermometer;
Memory _memory;
}
代码CPP文件:
#include "luminary.h"
#include "Led.h"
#include "Thermometer.h"
#include "Memory.h"
//Constructor
Luminary::Luminary(Led led,Thermometer thermometer,Memory memory){
_memory = memory;
_thermometer = thermometer;
_led = led;
}
为什么我会收到这些消息?
您需要为'Led','Thermometer'和'Memory'定义默认构造函数。 –
@ForhadAhmed:不太可能。这是一个基本的“分配而不是初始化”的错误,并且通过给予零的默认构造函数来解决这个问题并不是适当的解决方案。 –