当我尝试声明 log_.h 时,我将其包含在rckt_test.ino中(等于.cpp)编译器给出了我的异常:rckt_test.ino: 9:6: error: 'log_ log' redeclared as different kind of symbol
log_ log
。但我之前从未在其他任何地方宣布过这门课程。甚至可以在函数外声明 log _ 类吗?
rckt_test.ino(的.cpp):
#include <Arduino.h>
#include "log_.h"
// Settings
bool log_file = true; // Depends on availabilty of SD Cart reader
// Defining log class
log_ log;
void setup() {
Serial.begin(9600);
log.log_init(log_file);
log.log_text("Rocket startup");
}
void loop() {
}
log_.h :
#pragma once
#include <Arduino.h>
class log_ {
private:
void print_text(String text);
void save_to_log_file(String text);
static bool log_in_file;
public:
void log_init(bool file_loggging);
void log_text(String text);
};
错误:
Compiling debug version of 'rckt_test' for 'Arduino Nano w/ ATmega328P'
rckt_test.ino: 9:6: error: 'log_ log' redeclared as different kind of symbol
log_ log
arduino.h:26: In file included from
rckt_test.ino: from
math.h:305: note previous declaration double log(double)
extern double log(double __x) __ATTR_CONST__
rckt_test.ino: In function void setup()
rckt_test.ino: 15:5: error: request for member 'log_init' in 'log', which is
of non-class type 'double(double)
log.log_init(log_file)
rckt_test.ino: 17:5: error: request for member 'log_text' in 'log', which is
of non-class type 'double(double)
log.log_text("Rocket startup")
log_.cpp: 29:42: error: no 'void log_::log_in_file_setter(bool)' member
function declared in class 'log_
void log_*: log_in_file_setter(bool setter) {
log_.cpp: 33:31: error: no 'bool log_::log_in_file_getter()' member function
declared in class 'log_
bool log_*: log_in_file_getter() {
Error compiling project sources
Debug build failed for project 'rckt_test'
答案 0 :(得分:3)
错误显示log
的另一个声明来自math.h
,这是数学对数的函数声明。将变量从log
重命名为其他内容,或将其包装在不同的namespace
。