Scope Resolution Operator ::

I am testing out the Scope Resolution Operator :: Here is my code ...

class Sensor { public: float temperature = 33.8; };

Sensor MySensor;

float temperature = 22.16;

void setup() { Serial.begin(9600); }

void loop() { Read_Temperature(); }

void Read_Temperature(){ float temperature = 28.77; Serial.println(temperature); Serial.println(::temperature); Serial.println(MySensor::temperature); delay(5000); Serial.println(); }

I get an error "MySensor is not a class, namespace, or enumeration" Not sure what the issue is? Any help gratefully received. Thanks

  Serial.println(MySensor.temperature);

Thank you "wildbill", worked perfectly Thanks for your quick reply

If you want to reference a class static member variable you can use the class name for the scope:

class Sensor
{
  public:
    static constexpr float temperature = 33.8;
};


Sensor MySensor;


float temperature = 22.16;


void setup()
{
  Serial.begin(9600);
}


void loop()
{
  Read_Temperature();
}


void Read_Temperature()
{
  float temperature = 28.77;
  Serial.println(temperature);  // Local
  Serial.println(::temperature);  // Global
  Serial.println(Sensor::temperature);  // class static
  delay(5000);
  Serial.println();
}