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.

有帮助吗?

解决方案

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?

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top