Why we need our own header files?

When we write a program to implement something in real world, it can be large and complex. To overcome this problem, it’s the best solution to divide the program into small modules.

Whenever, we work with C++ programming language, basically we need three things the most to be done, that is:

1. Different functions to be declared to perform the task
2. Definitions of all the functions declared
3. Calling of all to perform the action

If we’ll do all this in the same file then it’ll be very difficult to read the code for future. So, best thing we do here is, we make seperate 3 files:

1. Where all functions are declared
2. Where all are defined
3. main calling

So, we make our own header files to keep the functions seperate from function definition. If any function is going to be used frequently in our programs then we should create header files containing the required classes and function decalarations.

To use this, we have to simply place the name of header file into our program with preprocessor directive #include

This makes the code more readable and easy to understand.

In real world examples and in major projects, this system is often used, e.g. in Slot machine, Water distribution and GD’s BakaPlan

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s