Forward Declaration of a Base Class

前端 未结 6 631
旧巷少年郎
旧巷少年郎 2020-12-10 01:57

I\'m trying to create proper header files which don\'t include too many other files to keep them clean and to speed up compile time.

I encountered two problems while

6条回答
  •  旧巷少年郎
    2020-12-10 02:45

    In both cases the compiler needs to know the size of the type. Therefore, a forward declaration will not suffice. A base class could add members or require a virtual table. The string member would require the size of the class to be increase to store the size of the STL string class.

    Forward declaring STL classes is often inadvisable since the implementations commonly include explicit template instantiations that speed up compilation.

提交回复
热议问题