Having issue with global variable

I know it's generally not good practice to use global variable but here's my problem anyways:

HEADER.h file:
1
2
3
4
5
6
7
8
9
#ifndef TEXTHEAD
#define TEXTHEAD
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
bool USEFIN = false; //Global
#endif
//...FUNCTION PROTOTYPES BELOW 


I also have a TextEdit.cpp (where main() is) and a MyFuncs.cpp (where all my functions are). Both TextEdit.cpp & MyFuncs.cpp both have the following line at the top:
#include "HEADER.h"

Yet when I compile I get this error:
1
2
1>TextFunctions.obj : error LNK2005: "bool USEFIN" (?USEFIN@@3_NA) already defined in TextEditor.obj
1>C:\Users\cartpauj\Documents\Visual Studio 2008\Projects\TextEditor\Debug\TextEditor.exe : fatal error LNK1169: one or more multiply defined symbols found


Any ideas?
Last edited on
Add extern before the declaration of USEFIN and initialize it in a cpp file
Tried bool extern USEFIN = false; in TextEdit.cpp - FAILED!
Tried extern bool USEFIN = false; in TextEdit.cpp - FAILED!
Tried the same for MyFuncs.cpp and both failed.

What am I missing?

If i get rid of the header and functions file and combine it all into an overloaded main file it works just fine.
It should be like this:
1
2
//header file
extern bool USEFIN;

1
2
//source file
bool USEFIN = false;
Worked like a charm thanks!!!
Topic archived. No new replies allowed.