How to call a method (arduino) from an existing Class from my Custom class?

StackOverflow https://stackoverflow.com/questions/22129949

  •  19-10-2022
  •  | 
  •  

Domanda

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

È stato utile?

Soluzione

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!!!!!: ");
    }
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top