类构造函数声明了两次

Class Constructor declared twice

本文关键字:两次 构造函数 声明      更新时间:2023-10-16

在Arduino IDE中,我收到一个关于我的构造函数如何声明两次的错误。

这是它的代码:

托德·

#ifndef TOND_H
#define TOND_H
class Tondeuse {
public:
  Tondeuse();
  Tondeuse(int,int);
};
#endif

嘟嘟.cpp

#ifndef TOND
#define TOND
#include "arduino.h"
#include "tond.h"

Tondeuse::Tondeuse()
{
}
Tondeuse::Tondeuse(int h, int w)
{
Serial.println("Hello");
}

#endif

和错误:

Tondeuse.cpp.o: In function `Tondeuse':
/tond.cpp:11: multiple definition of `Tondeuse::Tondeuse()'
tond.cpp.o:C:UsersDEPANNEAppDataLocal      Tempbuild6942484698459603114.tmp/tond.cpp:11: first defined here
Tondeuse.cpp.o: In function `Tondeuse':
/tond.cpp:11: multiple definition of `Tondeuse::Tondeuse()'
tond.cpp.o:C:UsersDEPANNEAppDataLocal   Tempbuild6942484698459603114.tmp/tond.cpp:11: first defined here
Tondeuse.cpp.o: In function `Tondeuse':
/tond.cpp:16: multiple definition of `Tondeuse::Tondeuse(int, int)'
tond.cpp.o:C:UsersDEPANNEAppDataLocalTempbuild6942484698459603114.tmp/tond.cpp:16: first defined here
Tondeuse.cpp.o: In function `Tondeuse':
/tond.cpp:16: multiple definition of `Tondeuse::Tondeuse(int, int)'
tond.cpp.o:C:UsersDEPANNEAppDataLocalTempbuild6942484698459603114.tmp/tond.cpp:16: first defined here

我没有两次包含它,也找不到任何问题。

您在Tondeuse.cpp中包含在tond.cpp中。不要包含实现文件。

如果该文件不再存在(重构),请确保在重新生成之前清理解决方案。