Question

So I have a custom class for the Arduino that I need to get the time from the ubiquitous Time.h http://playground.arduino.cc/Code/time#.UxNa6_1dLoo class.

Device.cpp

#include <Time.h> 
void Device::checkTimedEvent() {
    if(hour() == hour[timedIndex]) {
      Serial.println("TIME!!!!!: ");
    }
}

error

error: '((Device*)this)->Device::hour' cannot be used as a function

How do I expose hour() so Device.cpp can use it? Do I need to make an instance of Time or something? thanks

Was it helpful?

Solution

Device has a member variable named hour which takes precedence during name lookup. You need to use the scope operator to instruct the compiler to explicitly use the global function named hour.

#include <Time.h> 
void Device::checkTimedEvent() {
    if(::hour() == hour[timedIndex]) {
    // ^^ fully qualified name using scope operator 
        Serial.println("TIME!!!!!: ");
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top