I have a class called that has protected data:
class Sensors {
public:
/* other code here */
uint16_t getType()const { return type; } // accessors defined
float getValue()const { return value; }
bool getValid()const { return valid; }
protected:
uint16_t type=0;
float value=0;
bool valid=false;
};
class RoomControllers:public Sensors
{
public:
RoomControllers(); // constructor
void printStates() const;
void setTemperatureTarget();
private:
float targetTemperature=19.0; // default initialisation
bool currentlyHeating{false};
float targetHumidity=50;
bool currentlyHumidifying{false};
std::array<Sensors, 5> sensors; // C-style array replaced by C++ array
};
void RoomControllers::printStates() const
{
uint16_t validSensorCount = 0;
cout << "Sensors:" << endl;
cout << "--------" << endl;
// For each sensor, print its Type and Value
for (uint16_t count = 0; count < MAX_NUM_SENSORS; count++) {
if (sensors[count].valid) { // the problem is here
validSensorCount++;
Error says
error: ‘bool Sensors::valid’ is protected within this context
Please provide advice on how to access the valid variable without using a getter function.