The compiler is not recognizing my object heatingUnit as a type of the class HeatingUnit. I have no idea why?
// Jimoh Ovbiagele (JAO945)
#include <iostream>
#include <stdio.h>
#include <stdbool.h>
#include "HeatingUnit.h"
class BangBangControl{
public:
HeatingUnit *heatingUnit;
int tempToMaintain;
BangBangControl(int temp, bool isOn, int initialTemp)
: heatingUnit(new HeatingUnit(isOn, initialTemp)),
tempToMaintain(temp){
}
void setTemp(int newTemp){
tempToMaintain = newTemp;
}
int getTemp(){
return tempToMaintain;
}
int update(){
int i = heatingUnit.tick();
if (i > tempToMaintain + 2) heatingUnit.turnOff();
if (i < tempToMaintain - 2) heatingUnit.turnOn();
return i;
}
int main(){
BangBangControl bBC(50, true, 0);
for(int i = 0; i < 100; i++){
std::cout << "Temp to maintain is: " << bBC.getTemp() << " Current temp is: " << bBC.update() << "\n";
}
return(0);
}
};
I receive this error log
BangBangControl.cpp: In member function ‘int BangBangControl::update()’:
BangBangControl.cpp:31: error: request for member ‘tick’ in ‘((BangBangControl*)this)->BangBangControl::heatingUnit’, which is of non-class type ‘HeatingUnit*’
BangBangControl.cpp:32: error: request for member ‘turnOff’ in ‘((BangBangControl*)this)->BangBangControl::heatingUnit’, which is of non-class type ‘HeatingUnit*’
BangBangControl.cpp:33: error: request for member ‘turnOn’ in ‘((BangBangControl*)this)->BangBangControl::heatingUnit’, which is of non-class type ‘HeatingUnit*’
You’ve got a pointer to HeatingUnit which you need to dereference when you go to apply methods on it, so your update method should be: