Mel
Mel

Reputation: 2075

Including multiple classes in the same header file

I have an idea on how to do this, but I want to make sure I do it right....

I have five data classes. When I use one I typically use all of them (but not always).

Each class has a separate header file. I am getting sick of linking in each header file separately.

What is the best way resolve this issue?

Upvotes: 2

Views: 2622

Answers (1)

Dave DeLong
Dave DeLong

Reputation: 243156

Create a new header file called "DataFiles.h". Inside that, have your five #import statements. Then whenever you need the file classes, just #import "DataFiles.h".

Beware of circular dependencies.

(This is how Cocoa, Foundation, UIKit, CoreData, etc all behave. Notice that you just #import <Cocoa/Cocoa.h>, which imports everything else. Open up Cocoa.h and take a look)

Upvotes: 12

Related Questions