|
-
Feb 7th, 2001, 10:25 PM
#1
Thread Starter
PowerPoster
say i make a .h file that contains a class that i made. If i include the iostream.h file within the .h class file, and within the .cpp program file, so that it has been included twice within the project. Will this cause errors or anything. And will it include it twice, and then make the size of the final project bigger than it needs to be?
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
-
Feb 7th, 2001, 11:03 PM
#2
Lively Member
I don't think it will cause a problem. But I would suggest keeping your function declarations and stuff like that in the .h file and the code in the .cpp file. I guess it doesn't make much difference but it is more organized that way.
-
Feb 7th, 2001, 11:12 PM
#3
Thread Starter
PowerPoster
ok thanks, i was thinking more that if i sent a .h file to a friend and they didn't look at it and included it twice. But if it won't cause a problem that is good.
Thanks for the info
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
-
Feb 8th, 2001, 03:06 PM
#4
Frenzied Member
I think it does generate errors!!!
One should always use
Code:
#ifdef //If Defined
or
#ifndef //If NOT Defined
To prevent headers being included twice!
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Feb 8th, 2001, 04:21 PM
#5
Monday Morning Lunatic
Code:
#ifndef __FILE_H__ // change to your filename, including underscores
#define __FILE_H__
/* Code here */
#endif // __FILE_H__
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Feb 8th, 2001, 04:46 PM
#6
Frenzied Member
Why all the extra underscores? In the books I've read they recommend FILE_H, without the extras on the ends. Is that a standard thing or just your preference?
Harry.
"From one thing, know ten thousand things."
-
Feb 8th, 2001, 04:48 PM
#7
Monday Morning Lunatic
Mainly my preference, because if you notice, the usual preprocessor stuff has two underscores to start it, so anything small won't interfere with it.
It's by no means standard, but I've seen it used quite a bit, so that's what I've got.
Still, I suppose it's better than what ClassWizard generates
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Feb 8th, 2001, 06:59 PM
#8
Thread Starter
PowerPoster
thanks for the advice, one question though. This may be stupid but, where you say
/* Code here */
is that the code for the entier program/cpp file? or something else?
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
-
Feb 8th, 2001, 07:51 PM
#9
Frenzied Member
It's your header file code. At the beginning of your header file you write:
Code:
#ifndef FILE_H
#define FILE_H
then at the end of your header file you write
As you probably know, anything beginning with a # is a preprocessor instruction. Basically, if you haven't already included the file, then FILE_H (just an arbitrary keyword really) will be undefined. If the file has already been included at least once, then FILE_H will be defined and the preprocessor will skip over the code between the #ifndef and the #endif.
Harry.
"From one thing, know ten thousand things."
-
Feb 8th, 2001, 10:54 PM
#10
Thread Starter
PowerPoster
ok, i see. I didn't know you put the If in the header file. I thought you put it in the .cpp file.
Thanks a lot!
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
USAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSAUSA
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|