Forward declaration include, on top of declaration include (ClassFwd.h + Class.h)

前端 未结 4 1168
孤独总比滥情好
孤独总比滥情好 2020-12-16 01:08

In Effective C++ (3rd edition), Scott Meyers, in Item 31, suggests that classes should have, on top of their classic Declaration (.h) and Definition (.cpp) files, a Forward

4条回答
  •  半阙折子戏
    2020-12-16 01:30

    Placing a simple class Whatever; in its own header has no advantages and lots of disadvantages.

    Especially in the case where accessing a header can be time consuming, one uses simple forward declarations to avoid accessing headers; putting them in their own headers would defeat the purpose...

    With templated things, as you note, it's a different matter. E.g. check out from the standard library.

    Cheers & hth.

提交回复
热议问题