Reputation: 568
I am trying to create an object named luminary. This object is composed of thermometer object, memory object, Led Object. The last three classes are working perfectly separated. But when I try to glue everything together in the luminary class I got these message:
luminary.cpp:11:112: error: no matching function for call to ‘Thermometer::Thermometer()’
luminary.cpp:11:112: error: no matching function for call to ‘Memory::Memory()’
luminary.cpp:11:112: error: no matching function for call to ‘Led::Led()’
Code for header file of luminary class:
class Luminary{
public:
//Constructor
Luminary(Led led,Thermometer thermometer,Memory memory);
//Atributes
Led _led;
Thermometer _thermometer;
Memory _memory;
}
Code for cpp file:
#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;
}
Why do I get these messages?
Upvotes: 1
Views: 351
Reputation: 172934
According to your source, Led
, Thermometer
, Memory
have to be default constructible, means they should have a default constructor, but they haven't.
You could use member initializer list here:
Luminary::Luminary(Led led,Thermometer thermometer,Memory memory)
: _led(led), _thermometer(thermometer), _memory(memory) {}
Here is a discussion about why in moust cases, you should use initialization lists rather than assignment.
Upvotes: 4