我正在尝试创建一个抽象类,其他一些类可以作为 arduino 项目的基础。但是,每当我调用基础中的虚拟方法时,它只会调用基础实现。代码如下。谁能看到我做错了什么?
#define RTCBASE 0
class RTC_Base {
public:
virtual uint8_t begin(void){ return 0; };
virtual void adjust(const DateTime& dt){};
virtual DateTime now(){ return DateTime(); };
virtual int Type(){ return RTCBASE; };
};
////////////////////////////////////////////////////////////////////////////////
// RTC based on the DS1307 chip connected via I2C and the Wire library
#define DS1307 1
class RTC_DS1307 : public RTC_Base
{
public:
virtual int Type(){
return DS1307;
}
uint8_t begin(void);
void adjust(const DateTime& dt);
uint8_t isrunning(void);
DateTime now();
uint8_t readMemory(uint8_t offset, uint8_t* data, uint8_t length);
uint8_t writeMemory(uint8_t offset, uint8_t* data, uint8_t length);
};
///In Code
RTC_Base RTC = RTC_DS1307();
DateTime dt = RTC.now();
//The above call just returns a blank DateTime();