
template <typename T>struct foo { static int static_data; voID non_template_member() {} template <typename S> voID template_member(S) {}};template <typename T>int foo<T>::static_data = 0;template struct foo<int>;template struct foo<double>; 底部的显式实例化为类型int和double创建static_data和non_template_member()的定义. template_member(S)没有定义,因为它仍然是一个开放集.
如果没有为static_data提供[模板化]定义,则不会实例化相应的定义.
该标准的相关部分是14.7.2 [temp.explicit]第8段:
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 and members that are templates) that has not been prevIoUsly explicitly specialized in the translation unit containing the explicit instantiation,except as described below.
如果没有成员定义,则仅声明静态成员,并且显式实例化仅仅会看到实例化的声明.通过定义,显式实例化成为定义.
总结以上是内存溢出为你收集整理的c – 实例化模板是否实例化其静态数据成员?全部内容,希望文章能够帮你解决c – 实例化模板是否实例化其静态数据成员?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)