Solved

Use of header files

Posted on 2006-11-04
3
166 Views
Last Modified: 2013-11-20
Last night I discovered I could put parts of my program in new header files, include those header files in MyDlg.cpp, and make for a more orderly environment. So, I thought, I can put all my startup stuff in StartUp.h, all my ordring stuff in Orders.h, all my cancellation stuff in Cancellations.h. Then I thought it might be a good idea to ask if this approach will lead to problems down the road, so I haven't made more than a few new header files. Is this a workable approach? Is there a pitfall waiting down the road? Thanks
0
Comment
Question by:Elliot123
  • 2
3 Comments
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 17875668
No technical problems that I know of.  (But I don't see any real advantages either - it is just for your organising, as long as you are happier with it then do it).

If you have one .h/.cpp per class then (if you want to do so) you can easily copy/paste to another folder for use in another project.  However if the .h/.cpp had multiple classes then you might have to manually remove the undesired ones.
0
 
LVL 44

Expert Comment

by:AndyAinscow
ID: 17875671
copy/paste to another project - I mean the files themselves.
0
 
LVL 22

Accepted Solution

by:
mahesh1402 earned 250 total points
ID: 17879054
Putting all your code in files with a .h extension is no different from putting all your code in files with a .cpp extension, and it's just not good C++ design.

The more includes you put in your header file, the more often you have to recompile everything that depends on that header file.  If you put your includes in your implementation files where possible, then only those files that actually include a specific thrid file need to be recompiled when that third file is modified.  It may not matter in small projects, but in large ones  especially dealing with libraries it will matter a lot.

The purpose of the header file is to declare the interface to the outside world, and everything any user needs to know about how to interface with your code should be specified there, where they can see it in one place.

-MAHESH


0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question