我有一个带有各种静态元素的简单类。只要我不调用sprintf,所有编译都可以。当包含sprintf时(在最后一行的旁边),会发生非静态成员错误。
这是我对c ++的首次尝试;其他500行代码将进行干净编译。我有几个带有静态元素的类。
不确定如何清理。
class RTCClock {
private:
static unsigned long lastMillisCheck;
static RTC_DS1307 rtc;
const char daysOfTheWeek[7][12] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
static bool isInitialized(bool setInitialized) {
bool isInitialized = true;
int initAddress = 55; // use last vram entry
int initializedValue = 0xAF;
int initState = rtc.readnvram(initAddress);
if (initState != initializedValue) {
if (setInitialized) {
rtc.writenvram(initAddress, initializedValue);
rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
else {
isInitialized = false;
}
}
return isInitialized;
}
public:
static void Init() {
isInitialized(true);
}
static char* GetDateTime() {
char dtString[16];
DateTime dt = rtc.now();
char prototype[] = "%d/%d-%d:%d:%d";
sprintf(dtString, prototype, dt.month, dt.day, dt.hour, dt.minute, dt.second);
return dtString;
}
};