Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7539781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:28:26+00:00 2026-05-30T07:28:26+00:00

Im receiving this error when trying to compile my code. $ g++ -o BangBangControlTest

  • 0

Im receiving this error when trying to compile my code.

$ g++ -o BangBangControlTest BangBangControl.o BangBangControlTest.o
ld: duplicate symbol _heating_unit in BangBangControlTest.o and BangBangControl.o for architecture x86_64
collect2: ld returned 1 exit status

I am new to C++ and can’t find out what is wrong. I’ve searched through many tutorials and looked at similar error messages received by other stack users. Here are my classes.
“BangBangControlTest.cpp”

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

int main(){
  BangBangControl control(50, true, 75);

for(int i = 0; i < 50; i++){
std::cout << "Temp = " << control.update() << endl;
}

return 0;

}

“BangBangControl.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”

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

HeatingUnit heating_unit;
int temp_to_maintain;

class BangBangControl{

 public:
   BangBangControl(int, bool, int);
    void setTemp(int);
    int getTemp();
    int update();
 };

“HeatingUnit.cpp”

// HeatingUnit class implementation

#include <iostream>
#include "HeatingUnit.h"

using namespace std;

HeatingUnit::HeatingUnit(bool a, int b){
  isOn = a;
  temp = b;
}

void HeatingUnit::turnOn(){isOn = true;}

void HeatingUnit::turnOff(){isOn = false;}

int HeatingUnit::tick(){
  if(isOn && temp <= 100){
    return ++temp;

}
  else if((!isOn) && temp >= 0){
    return --temp;
  }
  else{
    return temp;
  }
}

“HeatingUnit.h”

#include <iostream>
using namespace std;

class HeatingUnit{
  public:
    bool isOn;
    int temp;

    HeatingUnit();
    HeatingUnit(bool, int);
    void turnOn();
    void turnOff();
    int tick();
};
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T07:28:28+00:00Added an answer on May 30, 2026 at 7:28 am

    You see that HeatingUnit heating_unit; in your header file? You need to put extern in front of it, and copy the original version without the extern to the .cpp file, optionally specifying an initial value there.

    You can read more about this here: How do I use extern to share variables between source files?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am receiving this error >GXRenderManager.obj : error LNK2001: unresolved external symbol private: static
I'm receiving this error when trying to see a report.
I am receiving this error when trying to execute applescript from my java application.
I'm trying to mock MouseButtonEventArgs.GetPosition() with Moq, but I keep receiving this error: System.ArgumentException:
I am receiving this error when trying to use RedirectToAction, can anyone offer any
i am receiving this error when trying to add user location. I have a
I'm receiving this error while I'm trying to connect to a database from a
I am trying to compile a code in C++ using code from : https://stackoverflow.com/questions/5953979/sending-and-receiving-array-using-mpi-part-2
I'm receiving this error while trying to use apc_store() . I googled it and
I am receiving this error when trying to use Python Server Pages with Mod_Python

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.