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

  • Home
  • SEARCH
  • 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 9218647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:54:44+00:00 2026-06-18T02:54:44+00:00

Possible Duplicate: Why does this not prevent multiple function declarations? Global.h #ifndef Global_h #define

  • 0

Possible Duplicate:
Why does this not prevent multiple function declarations?

Global.h

#ifndef Global_h
#define Global_h

#include <iostream>

unsigned char exitStatus;

#endif

OutputHandler.h

#ifndef OutputHandler_h
#define OutputHandler_h

#include "Global.h"

class OutputHandler {
private:
    static bool instanceExists;
// more code  

#endif

Root.h

#ifndef Root_h
#define Root_h

// declarations

OutputHandler *output;

#endif

Root.cpp

#include "Root.h"
// gets instance of OutputHandler
// more code

I am getting errors regarding exitStatus, static bool instanceExists, and static class output being already defined by Root.obj in OutputHandler.obj. I assume the issue is with including the header file OutputHandler.h in both Root.h and OutputHandler.cpp. Anyone know how to fix this or how to better organize header files?

  • 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-06-18T02:54:46+00:00Added an answer on June 18, 2026 at 2:54 am

    Because include guards only work at the translation unit level (you can, for this simple case, consider a single C file to be a translation unit).

    That means a single C file, if it includes the header file twice, will not process it the second time due to the include guards.

    However, if you include the header from two different C files, each of them will get a copy of the variables defined in that header.

    Then, when you link them together, you get the duplicates.

    The easiest way to get around this problem is to never define things in headers, only declare them.

    So, in the header (eg, xyzzy.h), you have:

    extern int xyzzy;  // declare but don't define.
    

    and in all the C files that want to use that, put:

    $include "xyzzy.h"
    

    and, in one of those C files, also put:

    int xyzzy;        // define it here, once.
    

    You can think of declaration as a simple “I declare that this exists somewhere, just not here”, while definition is “I an creating this here and now”.

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

Sidebar

Related Questions

Possible Duplicate: Why does this simple std::thread example not work? Code: #include <iostream> #include
Possible Duplicate: Why does this intentionally incorrect use of strcpy not fail horribly? Below
Possible Duplicate: can't access global variables inside a usort function? I've experienced this problem
Possible Duplicate: Why does this Random Number Generator not random? I have this test
Possible Duplicate: Collection initialization syntax in Visual Basic 2008? This does not compile. Dim
Possible Duplicate: Why does this code not increment a counter properly? I have a
Possible Duplicate: What does this mean? (function (x,y)){…}){a,b); in JavaScript I have the following
Possible Duplicate: C# switch variable initialization: Why does this code NOT cause a compiler
Possible Duplicate: How does this JavaScript/JQuery Syntax work: (function( window, undefined ) { })(window)?
Possible Duplicate: How does this CSS triangle shape work? Please help me i need

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.