Advertisement

Making header files??

Started by August 13, 2002 08:34 PM
6 comments, last by Sand_Hawk 22 years, 3 months ago
Ok, I''ve seen some topics on this but I still don''t understand it completely. When I make a header file I do it like this:
  
// .H file

#ifndef MY_HEADER
#define MY_HEADER

// Includes


// Other stuff

#endif MY_HEADER
  

  
// .CPP file

#include "Header.h"

// Functions

  
Now I want to include this in my project. I including the .h file in my game.cpp file enough or do I need to add the header and cpp file to my project(MSVC6)? And how do I turn my newly created header file into precompiled format and wich files do I need to distribute to my friends if they want em? thx and sorry for the question that has been asked 1000 times before. Sand Hawk ---------------- -Earth is 98% full. Please delete anybody you can.
My Site
----------------(Inspired by Pouya)
This code:
#ifndef MY_HEADER
#define MY_HEADER
// Includes
// Other stuff
#endif MY_HEADER
is not exactly essential for a header file. What it does is ensures that your compiler
only includes the file once . the #ifndef is like an if statement that checks to see if
your header has been included already. It does this by checking if the constant MY_HEADER
was defined. If you only included your file once then MY_HEADER was not defined , so you
define it (#define MY_HEADER). Now if you accidently included your file twice like so:

#include my_header.h
#include my_header.h

when the compiler processes the #ifndef MY_HEADER line in my_header for the second time
it sees that MY_HEADER was already defined and skips right to the #endif MY_HEADER. It''s
confusing , but this is pretty much how it works (i think , i might be wrong). But if you dont
under stand how it works just know that it prevents your header from being included into
your executable twice.

*Inhales*

Now , im VC++ when you create a header it should be automatically be added to your project.
I think there is a little edit box that you specify what project to add it to. As for headers that werent
created within a project i think they do have to be added to the project , but even if they dont need
to be added to a project its still a good idea to do so.

Hope this helps you
Advertisement
This code:
#ifndef MY_HEADER
#define MY_HEADER
// Includes
// Other stuff
#endif MY_HEADER
is not exactly essential for a header file. What it does is ensures that your compiler
only includes the file once . the #ifndef is like an if statement that checks to see if
your header has been included already. It does this by checking if the constant MY_HEADER
was defined. If you only included your file once then MY_HEADER was not defined , so you
define it (#define MY_HEADER). Now if you accidently included your file twice like so:

#include my_header.h
#include my_header.h

when the compiler processes the #ifndef MY_HEADER line in my_header for the second time
it sees that MY_HEADER was already defined and skips right to the #endif MY_HEADER. It''s
confusing , but this is pretty much how it works (i think , i might be wrong). But if you dont
under stand how it works just know that it prevents your header from being included into
your executable twice.

*Inhales*

Now , im VC++ when you create a header it should be automatically be added to your project.
I think there is a little edit box that you specify what project to add it to. As for headers that werent
created within a project i think they do have to be added to the project , but even if they dont need
to be added to a project its still a good idea to do so. As for what files you need to distribute , Unless
you are drawing data from external files (via fopen() or other functions like that) you should only need
to distribute the resulting exe file. All source , header and resource files get compiled into your exe file.

Hope this helps you
This code:
#ifndef MY_HEADER
#define MY_HEADER
// Includes
// Other stuff
#endif MY_HEADER
is not exactly essential for a header file. What it does is ensures that your compiler
only includes the file once . the #ifndef is like an if statement that checks to see if
your header has been included already. It does this by checking if the constant MY_HEADER
was defined. If you only included your file once then MY_HEADER was not defined , so you
define it (#define MY_HEADER). Now if you accidently included your file twice like so:

#include my_header.h
#include my_header.h

when the compiler processes the #ifndef MY_HEADER line in my_header for the second time
it sees that MY_HEADER was already defined and skips right to the #endif MY_HEADER. It''s
confusing , but this is pretty much how it works (i think , i might be wrong). But if you dont
under stand how it works just know that it prevents your header from being included into
your executable twice.

*Inhales*

Now , im VC++ when you create a header it should be automatically be added to your project.
I think there is a little edit box that you specify what project to add it to. As for headers that werent
created within a project i think they do have to be added to the project , but even if they dont need
to be added to a project its still a good idea to do so. As for what files you need to distribute , Unless
you are drawing data from external files (via fopen() or other functions like that) you should only need
to distribute the resulting exe file. All source , header and resource files get compiled into your exe file.

Hope this helps you
This code:
#ifndef MY_HEADER
#define MY_HEADER
// Includes
// Other stuff
#endif MY_HEADER
is not exactly essential for a header file. What it does is ensures that your compiler
only includes the file once . the #ifndef is like an if statement that checks to see if
your header has been included already. It does this by checking if the constant MY_HEADER
was defined. If you only included your file once then MY_HEADER was not defined , so you
define it (#define MY_HEADER). Now if you accidently included your file twice like so:

#include my_header.h
#include my_header.h

when the compiler processes the #ifndef MY_HEADER line in my_header for the second time
it sees that MY_HEADER was already defined and skips right to the #endif MY_HEADER. It''s
confusing , but this is pretty much how it works (i think , i might be wrong). But if you dont
under stand how it works just know that it prevents your header from being included into
your executable twice.

*Inhales*

Now , im VC++ when you create a header it should be automatically be added to your project.
I think there is a little edit box that you specify what project to add it to. As for headers that werent
created within a project i think they do have to be added to the project , but even if they dont need
to be added to a project its still a good idea to do so. As for what files you need to distribute , Unless
you are drawing data from external files (via fopen() or other functions like that) you should only need
to distribute the resulting exe file. All source , header and resource files get compiled into your exe file.

Hope this helps you
It doesn''t really helps alot, but thx for the time. Also, you didnt needed to post it 4 times . The stuff about the inclusion guards aren''t new to me. Just the Q about how to precompile em and if I need to specificly add them to the project or isn''t that necesarry?

Sand Hawk

----------------
-Earth is 98% full. Please delete anybody you can.


My Site
----------------(Inspired by Pouya)
Advertisement
Sand_Hawk:

Yeah, you have to add them to the project. Once you''ve done that, VC++ won''t recompile them unless you''ve made changes to the code. If you want to send it to your friends (with VC++ I presume), just send all of the .cpp and .h files, along with the workspace and other VC++ created files in a .zip file.

John.
thx JohnAD. This was the answer I was looking for.

Sand Hawk

----------------
-Earth is 98% full. Please delete anybody you can.


My Site
----------------(Inspired by Pouya)

This topic is closed to new replies.

Advertisement