?
Solved

Use of header files

Posted on 2006-11-04
3
Medium Priority
?
172 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 750 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

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses
Course of the Month14 days, 21 hours left to enroll

770 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