Solved

Use of header files

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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Suggested Solutions

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.

821 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