Do Explicit Instantiations of C++ Class Templates Instantiate Dependent Base Classes?

后端 未结 1 1590
误落风尘
误落风尘 2021-02-19 13:06

I figured an explicit instantiation request would automatically instantiate all base class members also, but I get a linker error: unresolved external symbol \"public: voi

相关标签:
1条回答
  • 2021-02-19 13:53

    The Standard says

    The explicit instantiation of a class template specialization implies the instantiation of all of its members not previously explicitly specialized in the translation unit containing the explicit instantiation.

    In other words, it does not mandate that base classes are explicitly instantiated in turn. It will cause an implicit instantiation of them which will not instantiate their member definitions up-front. It's some ugly glitch in the Standard as to whether some text when it says "member" means "direct" or "inherited" member, as that often seems to be "obvious" to the one who wrote the Standards wording, but not to the one who reads it. C++0x has added some clarifications (it also has a difference between explicit instantiation declarations and definitions that C++03 doesn't have, but even ignoring that, the C++0x wording contains some more bits of insight):

    An explicit instantiation that names a class template specialization is also an explicit instantiation of the same kind (declaration or definition) of each of its members (not including members inherited from base classes) that has not been previously explicitly specialized in the translation unit containing the explicit instantiation, except as described below. [ Note: In addition, it will typically be an explicit instantiation of certain implementation-dependent data about the class. — end note ]

    0 讨论(0)
提交回复
热议问题