multiuse headers/classes

Hi guys, I am a fairly decent programmer in general, but still consider myself a noob (cos I odn't know stuff like this yet). Anyway I have a quick one for you:

I have created lots of classes and subsystems for an application I am building, but some classes are like utility classes (e.g. linked lists etc...) and I use them over and over again in all the other classes. I currently have an include in every class, and I would like to know how to get round this because, when I run the app I get linked list already defined...

I know I can just put the 'include' statement in the main cpp file above all the classes that use linked list for example, but is there anyway to say 'include only if not already included...'? This would not make my app run any better but it means that my classes can stand alone OR work together without changing source code.

Sorry if this is a simple one, I don't know what to search for otherwise I'd search myself lol, even the title of this post is ambiguous. However it, sounds like something c++ is capable of so hopefully one of you guys knows :D

Thanks,

James
but is there anyway to say 'include only if not already included...'?

Yes. Read this:

http://www.cplusplus.com/forum/articles/10627/#msg49679

Specifically sections 3 and 4.
closed account (3pj6b7Xj)
To put it plain simple terms, use

1
2
3
4
5
6
#ifndef mycode_h_
#define mycode_h_

// what to include only once goes here...(ie. your code)

#endif 


And after that read the link Disch posted and it will all make much more sense.

Happy C++ing!
Topic archived. No new replies allowed.