Few questions about header file...

I'm still learning C++ and there are things that I don't understand about header file...


1. I have 3 files.(main.cpp, Foo.h, Foo.cpp)
and this is how I compile with g++ command prompt.

g++ main.cpp Foo.cpp -o something.exe
How is this working? why do I not put header file?
How does C++ compiling work?

I heard about object file. What is it and how do I make one?


2.
1
2
3
4
#ifndef FOO_H
#define FOO_H

#endif 


Can you explain what these stuffs do?

3. I heard that if you include your header file like this,
#include "thingie.h"

it will look at my project folder. Is it true?
#1) I answered a very similar question to this in this thread:

http://www.cplusplus.com/forum/general/159254/#msg813367




#2) It's an include guard. It prevents the contents of the header being declared multiple times if you include the header more than once. More details here:

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




#3) First it will look in whatever folder the source file is in.
If it doesn't find it there, it will start looking in whatever folders your compiler is configured to look in. You can configure most/all compilers to look in a specific "project" directory.
Topic archived. No new replies allowed.