I'm having trouble using my homemade .h files in my multi-source projects. If I I only include the .h in one of the sources I can't use it in the others. But if I include it other sources it's considered redefining the include and it won't compile. Other .h's besides the ones that I make do this to. I've noticed that some though (such as iostream) don't have this problem and I could include it in the same source 10 times if I wanted to. can someone please help me out with this so that I can make header files that can be declared more than once in the same project?
goody11
-2
Junior Poster
Recommended Answers
Jump to PostLet's try this again. ITTY BITTY EDitting window.
#include <iostream> #include "hello.h" int main() { hi(); system("pause"); return 0; } void hi() { std::cout << "Hi!" << std::cout; return; }
Jump to PostMake sure the iCOLOR enums are before the array!
I goofed and put it afterwards!
Jump to PostOne of the benefits about .h files is that you can include them in mulitple projects without having to retype the declaration each time. The linker will look up the definition/implementation each time you include it somewhere. Another benefit is that if you want to change the implementation you only …
Jump to PostPut each Functional type into its own CPP file and have a matching H file as a matching set. then merely include the H file.
As to your other note. Programming is an art. You examine the problem and think of the most flexible solution to solve that problem. …
Jump to PostThat one function you shown was a case of reuse. Reuse means things can be condensed, and arrays are great for condensing. I also noted that the "color##" strings used the same characters as represented by Hex and were always two digits. So no need for strings, merely a single …
All 28 Replies
wildgoose
420
Practically a Posting Shark
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
goody11
-2
Junior Poster
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
goody11
-2
Junior Poster
goody11
-2
Junior Poster
wildgoose
420
Practically a Posting Shark
Ancient Dragon
5,243
Achieved Level 70
Team Colleague
Featured Poster
wildgoose
420
Practically a Posting Shark
goody11
-2
Junior Poster
goody11
-2
Junior Poster
goody11
-2
Junior Poster
wildgoose
420
Practically a Posting Shark
wildgoose
420
Practically a Posting Shark
wildgoose
420
Practically a Posting Shark
goody11
-2
Junior Poster
Lerner
582
Nearly a Posting Maven
wildgoose
420
Practically a Posting Shark
goody11
-2
Junior Poster
wildgoose
420
Practically a Posting Shark
goody11
-2
Junior Poster
wildgoose
420
Practically a Posting Shark
wildgoose
420
Practically a Posting Shark
Lerner
582
Nearly a Posting Maven
goody11
-2
Junior Poster
wildgoose
420
Practically a Posting Shark
wildgoose
420
Practically a Posting Shark
goody11
-2
Junior Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.