Welcome to Dream.In.Code
Getting C++ Help is Easy!

Join 132,400 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,223 people online right now. Registration is fast and FREE... Join Now!




#include dependencies

 
Reply to this topicStart new topic

#include dependencies, Multiple headers (both custom and standard)

Delta_Echo
post 21 Aug, 2008 - 06:20 PM
Post #1


D.I.C Regular

***
Joined: 24 Oct, 2007
Posts: 421


My Contributions


When I create a header for use in a program, how exactly do the #include dependencies work? for example,
if I were to write a .h with a fucntion that uses Console-Out stream (cout) would I have to include the preprocessor
cpp

#include <iostream>

in the header or the main .cpp file where that header and function are used? Im just a little confused on this.
Thanks for reading smile.gif

User is offlineProfile CardPM

Go to the top of the page

NickDMax
post 21 Aug, 2008 - 06:55 PM
Post #2


2B||!2B

Group Icon
Joined: 18 Feb, 2007
Posts: 2,857



Thanked 47 times

Dream Kudos: 550
My Contributions


You actually only have to include <iostream> in the file that defines (not declares) your functions. So you do not have to put it into your custom .h unless somewhere in THAT FILE you use something requiring something inside of <iostream>.

That being said, people generally put all of the header needed by the particular .cpp file in the associated .h file. This just simplifies things. My custom mytable.cpp needs to only include mytable.h if that header file also includes all of standard libraries I want to use.

You only have to include a file once per compilation unit (c/cpp file). So long as it gets included before any of its symbols are used you are good.
User is offlineProfile CardPM

Go to the top of the page

Delta_Echo
post 21 Aug, 2008 - 07:22 PM
Post #3


D.I.C Regular

***
Joined: 24 Oct, 2007
Posts: 421


My Contributions


Thanks NickDMax :-)
User is offlineProfile CardPM

Go to the top of the page

Reply to this topicStart new topic
Time is now: 11/22/08 07:51AM

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month