目前,我有这个代码:
void writeLog(__FlashStringHelper* mes){
Serial.println(mes);
if(!logfile){
logfile = SD.open(logpath,FILE_WRITE);
if(!logfile) return;
}
logfile.write(mes);
}
void writeLog(char* mes){
Serial.println(mes);
if(!logfile){
logfile = SD.open(logpath,FILE_WRITE);
if(!logfile) return;
}
logfile.write(mes);
}
有没有办法重载函数来接受 char* 和 __FlashStringHelper* 而无需写入正文 2 次?
谢谢!
最佳答案
如果您可以使用模板,请尝试以下操作:
template <typename T>
void writeLog(T mes) {
Serial.println(mes);
if (!logfile) {
logfile = SD.open(logpath, FILE_WRITE);
if (!logfile) return;
}
logfile.write(mes);
}
关于c++ - 在函数中重载运算符而不写入主体 2 次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60617129/