#### Archived

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

## Recommended Posts

Skibum    122
Using MSVS 6.0 on a windows program I'm getting this annoying linker error for every function in one of my .h files. In every .h file i have, i have:
  #ifndef __THISFILE_H__ #define __THISFILE_H__ // all the functions and code here #endif // __THISFILE_H__ 
I've tried deleting the temp files, and doing a fresh compile, still the same. I can't figure out how it's linking these functions twice. What am i doing wrong? *Annoyed* Edit - Formatting Edited by - Skibum on November 6, 2001 7:56:38 PM

##### Share on other sites
Arild Fines    968
You _never_ put anything but inline functions in headers. The header guards are to prevent multiple inclusions from the same .cpp file...eg cpp includes header1 that includes header2 that includes header3 that includes header1. It will not prevent the compiler from seeing multiple globally defined functions.
Put only function _declarations_ in the header files, then put the _definitions_ in one, and only one, cpp file.

"I contend that we are both atheists. I just believe in one fewer god than you do. When you understand why you dismiss all the other possible gods, you will understand why I dismiss yours." - - Stephen Roberts

##### Share on other sites
Skibum    122
And by this you mean?

##### Share on other sites
Zipster    2365
Only put declarations in header files. Now and forever, until the end of time. Put actual implementation only into source files, now and forever, until the end of time. It''s good that you know how to use multiple inclusion protection, but you need to know what to have it protect

##### Share on other sites
Oluseyi    2107
quote:
Original post by Skibum
And by this you mean?

He means if you don''t know the difference between a declaration and a definition, you''d best to back up and hit that intro text again.

I wanna work for Microsoft!