36 Replies - 1684 Views - Last Post: 27 August 2009 - 12:06 PM
#1
WTF are header files exactly?
Posted 26 August 2009 - 08:48 AM
Replies To: WTF are header files exactly?
#2
Re: WTF are header files exactly?
Posted 26 August 2009 - 08:53 AM
I wrote about header organization a few days ago.
To clarify, you can put whatever you want in a header (it could even be empty, but that would be pointless), but there are "recommendations"/standards of what "should" go in there.
This post has been edited by KYA: 26 August 2009 - 08:53 AM
#3 Guest_Neumann*
Re: WTF are header files exactly?
Posted 26 August 2009 - 08:53 AM
The headers are the files that contain such declarations.
This post has been edited by Neumann: 26 August 2009 - 08:56 AM
#4
Re: WTF are header files exactly?
Posted 26 August 2009 - 09:20 AM
it's that primitive. in "more advanced" (not really- just prettier
#5
Re: WTF are header files exactly?
Posted 26 August 2009 - 09:22 AM
"" quotes indicate that the header is in the local directory
#6
Re: WTF are header files exactly?
Posted 26 August 2009 - 09:23 AM
#7
Re: WTF are header files exactly?
Posted 26 August 2009 - 09:23 AM
polymath, on 26 Aug, 2009 - 10:20 AM, said:
I find myself saying that about C++ a lot, in general.
NeoTifa, on 26 Aug, 2009 - 10:23 AM, said:
Kinda. You can think of it as a Java source file that contains just a class...no main method. Then when you use the #include, it's like import.
This post has been edited by Locke: 26 August 2009 - 09:24 AM
#8
Re: WTF are header files exactly?
Posted 26 August 2009 - 09:26 AM
Now hows about them pointer things?
This post has been edited by NeoTifa: 26 August 2009 - 09:27 AM
#9
Re: WTF are header files exactly?
Posted 26 August 2009 - 09:27 AM
NeoTifa, on 26 Aug, 2009 - 09:23 AM, said:
No! An interface has method declarations, but other java files do not explicitly include it aside from saying they implement it. If a java class implements an interface it MUST override each method with one of its own. In C++, any file that needs the declaration of it includes it (see my link above). Headers lay out the framework for other files. Main.cpp needs to know what a Cat is, but doesn't care about the implementation, it will look in the Cat.cpp object file (created by the compiler, similar to .class files in java) for what a Cat actually does.
Definition versus declaration. You never include other .cpp files, so if you need one file to know what another does, have it include its header. (I'm a big fan of matching named headers/cpp files).
Hope that helps. If it's still as clear as mud, let me know.
#10
Re: WTF are header files exactly?
Posted 26 August 2009 - 09:32 AM
KYA, on 26 Aug, 2009 - 10:27 AM, said:
Anyone that doesn't practice this needs to be shot on sight. It's so difficult to keep track of them when they're named differently...it's pathetic.
This post has been edited by Locke: 26 August 2009 - 09:33 AM
#11
Re: WTF are header files exactly?
Posted 26 August 2009 - 09:56 AM
Locke, on 26 Aug, 2009 - 11:23 AM, said:
primitive, but elegant in it's simplicity and efficiency. just finishing your sentences for you
serious now...
All a pointer is is basically a special kind of integer. You can imagine your computer's memory as consisting of a series of blocks. a pointer stores the number of one of those blocks. now why would this be useful?
A couple of reasons. when you call a functions with normal ints, it makes a copy of the variables. so in C (ie before reference variables like int&) you needed to pass a pointer so two functions could have access to the same memory.
The other place where you need to make an array of dynamic length. if you want an array that is equal in length to an int i (this was inputed by the user earlier. just go with it), you can't int array[i]; because the compiler can't make a static array like that. instead you say int * i = new int[i];. what this does is makes a pointer and then the new statement finds enough memory to fit i integers. it then sets the number of this block to i. then you can use it like any other array as long as you call delete i. if you need me to be more complete just reply.
#12
Re: WTF are header files exactly?
Posted 26 August 2009 - 10:22 AM
#13
Re: WTF are header files exactly?
Posted 26 August 2009 - 10:49 AM
Story: A pointer is in a cubby hole. It can hold the location of another cubby hole. In the pointer's cubby hole I put a piece of paper that tells me where an item is (in another cubby hole). I follow the directions on the piece of paper to get to the item I want. If I retrieve the contents of the pointer's cubby hole all I get is the piece of paper (memory address). If I dereference the pointer, I get what the piece of paper leads to.
This post has been edited by KYA: 26 August 2009 - 10:52 AM
#14
Re: WTF are header files exactly?
Posted 26 August 2009 - 10:59 AM
The cubby hole analogy was actually pretty good. What I also find good is seeing it graphically.
http://richardbowles...m/cpp/cpp18.htm
Try to think of pointers in a box and pointer diagram situation. If you retreive the value of the pointer (an arrow),
you'll just get the location of another value. But if you dereference the pointer, you can obtain the information
stored where the arrow is pointing. It's really similar to what KYA said, but it might help you understand
Zach
#15
Re: WTF are header files exactly?
Posted 26 August 2009 - 11:50 AM
|
|

New Topic/Question
Reply







MultiQuote






|