I have class called HighWaterDetector:
class HighWaterDetector {
public:
HighWaterDetector(Device* device);
NCD2Relay ncd2Relay;
// Output output1;
Output outputs[2];
CloudMsgParser cloudMsgParser;
Device * devicePtr;
};
How do I initialize the array of "Output" objects in the constructor of HighWaterDetector?
Output class:
class Output
{
public:
Output(ushort relayNum, NCD2Relay* ncd2RelayPtr);
ushort relayNum;
OutputStatus outputStatus;
int setOutputOn(void);
int setOutputOff(void);
void process(void);
NCD2Relay* ncd2RelayPtr;
};
with output constructor looking like:
Output::Output(ushort relayNum, NCD2Relay* ncd2RelayPtr2) {
this->relayNum = relayNum;
this->ncd2RelayPtr = ncd2RelayPtr2;
}
I am new to C++ and not sure if I can make the HighWaterDetector Constructor look like:
HighWaterDetector::HighWaterDetector(Device* device){
ncd2Relay = NCD2Relay();
outputs[0] = Output(1, &ncd2Relay);
outputs[1] = Output(2, &ncd2Relay);
cloudMsgParser = CloudMsgParser();
}
Getting compile errors:
highWaterDetector.cpp: In constructor 'HighWaterDetector::HighWaterDetector(Device*)':
highWaterDetector.cpp:8:52: error: no matching function for call to 'Output::Output()'
HighWaterDetector::HighWaterDetector(Device* device){
^
highWaterDetector.cpp:8:52: note: candidates are:
In file included from highWaterDetector.h:10:0,
from highWaterDetector.cpp:1:
output.h:20:2: note: Output::Output(ushort, NCD2Relay*)
Output(ushort relayNum, NCD2Relay* ncd2RelayPtr);
^
output.h:20:2: note: candidate expects 2 arguments, 0 provided
output.h:17:7: note: constexpr Output::Output(const Output&)
class Output
^
output.h:17:7: note: candidate expects 1 argument, 0 provided
output.h:17:7: note: constexpr Output::Output(Output&&)
output.h:17:7: note: candidate expects 1 argument, 0 provided
highWaterDetector.cpp: In constructor 'HighWaterDetector::HighWaterDetector(Device*)':
highWaterDetector.cpp:8:52: error: no matching function for call to 'Output::Output()'
HighWaterDetector::HighWaterDetector(Device* device){