I have a class named HighWaterDetector:
class HighWaterDetector
{
public:
HighWaterDetector(Device* device);
Device * devicePtr;
Output * output1Ptr;
CloudMsgParser * cloudMsgParserPtr;
Output output1;
NCD2Relay ncd2Relay;
CloudMsgParser cloudMsgParser;
};
with constructor:
HighWaterDetector::HighWaterDetector(Device* device): ncd2Relay(), output1(1, &ncd2Relay){
}
I am trying to initialize an instance of Output in the member initialization list for HighWaterDetector but Output which requires you to pass a pointer to an instance of NCD2Relay which is also a member of the class HighWaterDetector. My program crashes inside the output constructor. Is this the wrong way of doing this? What am I doing wrong?
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;
};
//Output Constructor
Output::Output(ushort relayNum, NCD2Relay* ncd2RelayPtr) {
this->relayNum = relayNum;
this->ncd2RelayPtr = ncd2RelayPtr; //DOESNT CRASH IF I COMMENT THIS OUT
this->outputStatus.outFail = 0;
Serial.print("Initializing output ");
Serial.println(this->relayNum);
this->setOutputOff();
}