Public Group

#### Archived

This topic is now archived and is closed to further replies.

# Inclusion Error in VC++

This topic is 5463 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

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.

##### Share on other sites
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

##### Share on other sites
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.

##### Share on other sites
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?

##### Share on other sites
extern int foo;

in one source file:
int foo;

##### Share on other sites
Perfect thanks. That was what I was looking for. It worked perfectly.

1. 1
2. 2
Rutin
24
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 17
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631758
• Total Posts
3002155
×