Solved

Use of header files

Posted on 2006-11-04
3
165 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Window placement 17 87
zeroMAx challenge 20 111
EvenOdd challenge 10 126
building a service to accessed via telnet client, want colors ? 4 92
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

856 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