我正在嘗試創建一個名爲的對象,名爲。該對象由溫度計對象,內存對象,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:不太可能。這是一個基本的「分配而不是初始化」的錯誤,並且通過給予零的默認構造函數來解決這個問題並不是適當的解決方案。 –