Thread: weird redefinition of bool error

  1. #1
    Registered User
    Join Date
    Mar 2007

    weird redefinition of bool error

    The compiler says there is a redefinition of BOOL bsuccess, at the same line. So basically it is a redefinition of itself?

    tables.h    4    error: `BOOL bsuccess' previously defined here
    tables.h    4    error: redefinition of `BOOL bsuccess'
    Says they are both on line 4. There are a couple other BOOLs that are having the same error below it. I have some BOOLs in other header files and they don't have this problem. What gives?

    BOOL bsuccess = false;
    BOOL bfail = false;

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    My guess is that you are including tables.h twice without include guards.

    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    The larch
    Join Date
    May 2006
    I don't think inclusion guards help against this. Each cpp file that includes the header, will see this definition again.

    If you really need globals, you should use the extern keyword.

    //in header
        extern BOOL success;
    //in one cpp file
        BOOL success = false;
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Actually, there are two ways of doing it.

    You could have only one definition, as you've done it. Or you could declare a different instance of success in each source file, by using the static keyword. This is probably not what you want, however, because each variable would be independent, and setting one variable would not effect the others.

    Your code works, however, when only one source file is including the header file.

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell

    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ:

    My website:
    Projects: codeform, xuni, atlantis, nort, etc.

  5. #5
    Registered User
    Join Date
    Mar 2007
    Thanks guys. I was declaring tables.h in two different files. Once in the .cpp file and again in another header file for some reason.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. We Got _DEBUG Errors
    By Tonto in forum Windows Programming
    Replies: 5
    Last Post: 12-22-2006, 05:45 PM
  2. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  4. pointer to array of objects of struct
    By undisputed007 in forum C++ Programming
    Replies: 12
    Last Post: 03-02-2004, 04:49 AM
  5. Linking error
    By DockyD in forum C++ Programming
    Replies: 10
    Last Post: 01-20-2003, 05:27 AM