Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/138.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 什么是;重复符号“BangBangControlTest.o和BangBangControl.o中的“加热”单元”;什么意思?_C++_Gcc_Compiler Construction - Fatal编程技术网

C++ 什么是;重复符号“BangBangControlTest.o和BangBangControl.o中的“加热”单元”;什么意思?

C++ 什么是;重复符号“BangBangControlTest.o和BangBangControl.o中的“加热”单元”;什么意思?,c++,gcc,compiler-construction,C++,Gcc,Compiler Construction,我在编译代码时收到了这个错误 #include <iostream> #include "BangBangControl.h" using namespace std; BangBangControl::BangBangControl(int temp, bool isOn, int initialTemp){ heating_unit = HeatingUnit(isOn, initialTemp); temp_to_maintain = temp; } void Ba

我在编译代码时收到了这个错误

#include <iostream>
#include "BangBangControl.h"
using namespace std;

BangBangControl::BangBangControl(int temp, bool isOn, int initialTemp){
  heating_unit = HeatingUnit(isOn, initialTemp);
  temp_to_maintain = temp;
}

void BangBangControl::setTemp(int temp){temp_to_maintain = temp;}
int BangBangControl::getTemp(){return temp_to_maintain;}
int BangBangControl::update(){
  int b=heating_unit.tick();
  if (b  > temp_to_maintain + 2) heating_unit.turnOff();  if (b  < temp_to_maintain - 2) heating_unit.turnOn();
  return b;
}
$g++-o BangBangControlTest BangBangControl.o BangBangControlTest.o
ld:BangBangControlTest.o和BangBangControl.o中用于架构x86_64的重复符号_加热_单元
collect2:ld返回1个退出状态

#include <iostream>
#include "BangBangControl.h"
using namespace std;

BangBangControl::BangBangControl(int temp, bool isOn, int initialTemp){
  heating_unit = HeatingUnit(isOn, initialTemp);
  temp_to_maintain = temp;
}

void BangBangControl::setTemp(int temp){temp_to_maintain = temp;}
int BangBangControl::getTemp(){return temp_to_maintain;}
int BangBangControl::update(){
  int b=heating_unit.tick();
  if (b  > temp_to_maintain + 2) heating_unit.turnOff();  if (b  < temp_to_maintain - 2) heating_unit.turnOn();
  return b;
}
我是C++新手,没法找出错误。我搜索了许多教程,并查看了其他堆栈用户收到的类似错误消息。这是我的课。 “BangBangControlTest.cpp”

#include <iostream>
#include "BangBangControl.h"
using namespace std;

BangBangControl::BangBangControl(int temp, bool isOn, int initialTemp){
  heating_unit = HeatingUnit(isOn, initialTemp);
  temp_to_maintain = temp;
}

void BangBangControl::setTemp(int temp){temp_to_maintain = temp;}
int BangBangControl::getTemp(){return temp_to_maintain;}
int BangBangControl::update(){
  int b=heating_unit.tick();
  if (b  > temp_to_maintain + 2) heating_unit.turnOff();  if (b  < temp_to_maintain - 2) heating_unit.turnOn();
  return b;
}
//测试函数
#包括
#包括“BangBangControl.h”
使用名称空间std;
int main(){
邦邦控制(50,对,75);
对于(int i=0;i<50;i++){

std::cout您可以在头文件中看到
HeatingUnit heating\u unit;
吗?您需要将
extern
放在它前面,并将没有extern的原始版本复制到.cpp文件中,可以选择在那里指定初始值

#include <iostream>
#include "BangBangControl.h"
using namespace std;

BangBangControl::BangBangControl(int temp, bool isOn, int initialTemp){
  heating_unit = HeatingUnit(isOn, initialTemp);
  temp_to_maintain = temp;
}

void BangBangControl::setTemp(int temp){temp_to_maintain = temp;}
int BangBangControl::getTemp(){return temp_to_maintain;}
int BangBangControl::update(){
  int b=heating_unit.tick();
  if (b  > temp_to_maintain + 2) heating_unit.turnOff();  if (b  < temp_to_maintain - 2) heating_unit.turnOn();
  return b;
}
您可以在此处阅读更多关于此的信息:

#include <iostream>
#include "BangBangControl.h"
using namespace std;

BangBangControl::BangBangControl(int temp, bool isOn, int initialTemp){
  heating_unit = HeatingUnit(isOn, initialTemp);
  temp_to_maintain = temp;
}

void BangBangControl::setTemp(int temp){temp_to_maintain = temp;}
int BangBangControl::getTemp(){return temp_to_maintain;}
int BangBangControl::update(){
  int b=heating_unit.tick();
  if (b  > temp_to_maintain + 2) heating_unit.turnOff();  if (b  < temp_to_maintain - 2) heating_unit.turnOn();
  return b;
}