Skip navigation

I was having a problem with a common C++ pattern:

//file1.h #include "file2.h" // file2.h #include "file1.h"

The header cross-inclusion sometimes results in compilation errors if “file1.h” requires a type from “file2.h” to be fully defined, and vice-versa.

So, what I started doing is stop #including every header file in every other header file and use forward declarations instead, and include the required header file in the code file that uses the class definition.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: