I need to make a Fan GUI program that asks for if the fan is on and what speed the fan is on. I've got the general code done but im getting an error with my Bool Fan::isOn() function. It's says declaration is incompatible and i cant see what i did wrong that function is the only one that's not working. Here's my code.
FanHeader.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <iostream>
#include <string>
#include <limits>
usingnamespace std;
class Fan
{
public:
Fan();
int getSpeed();
void setSpeed(int speed);
bool isOn();
void setOn(bool trueOrFalse);
private:
int speed;
bool isOn;
};
fanheader.h
Lines 13 & 17: Your function name is the same as your variable name. This is confusing the compiler. Does isOn refer to the variable or the address of the function?
fanmpl.cpp
Line 4-5: I would argue that if the fan speed is 1, the fan is on.
You have a logical error at line 20. You should be returning isOn (or whatever you rename the variable to).
Is it really necessary to have both a speed variable and a isOn variable? I would suggest changing the isOn() function to:
1 2 3
bool Fan::isOn()
{ return speed > 0; // if speed is 0, fan is stopped
}