Solved

Use of header files

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
This video discusses moving either the default database or any database to a new volume.

747 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now