user870130
user870130

Reputation: 575

Forward Declare in Header and Include in CPP?

I have begun to forward declare what I can in the header. However, the majority of the time I am only postponing the #include to the corresponding cpp file.

This article has led me to believe I should be doing this. However, in practice I've never seen someone else's code with such copious amounts of forward declares with a corresponding include in the cpp file.

I am wondering, if I am misinterpreting or over applying this rule and in the process making my project less readable.

Upvotes: 0

Views: 182

Answers (1)

Abhishek Bansal
Abhishek Bansal

Reputation: 5345

Using forward declaration wherever possible is a good idea as it will speed up your compilation time. Most people don't use it because generally they don't know or they are lazy or they are ignorant. But this provides significant compilation time boost up in big projects. I don't see any reason why it will decrease readability of code.

See this SO question C/C++ Forward declaration vs. Include
Also this Should one use forward declarations instead of includes wherever possible?

Upvotes: 2

Related Questions