Inclusion Error in VC++

Started by
4 comments, last by CodeMaster000 20 years, 8 months ago
I though some variables into a header file that I call many times. The header file has inclusion guards on it and yet it keeps saying 3 times the object are allready declared. I had this problem before but I forgot the trick to fix it. Can someone help.
Advertisement
Yes one thing is you might have multiple cpp, c and or .h files that somehow include the header file more than once, best thing I can recommend is to check all your source files to see if you find a header file declared more than once.

- BlueDev
[/quote]
Well, if I guess right, then you are defining objects in the header file. This should be avoided. Rather, declare your objects as extern in the header and define them properly in one of your .cpp files.
How can I use the same variables in different cpp files? Should I put them in a header or is the a command where I can declare them in each cpp file without having each decloration taken seriously?
In the header file:
extern int foo; 


in one source file:
int foo; 


Kippesoep
Perfect thanks. That was what I was looking for. It worked perfectly.

This topic is closed to new replies.

Advertisement