模板类的虚成员函数什么时候实例化? [英] When the virtual member functions of a template class instantiated?
问题描述
我知道模板类的普通成员函数在第一次使用时都会被实例化.但是这不能用于虚拟成员函数,因为它可以通过基类指针访问.这是否意味着一旦模板类被实例化,虚成员函数就会被实例化?如果没有,什么时候?
I know that the normal member function of a template class will be instantiated whenever it is used for the first time. But this cannot be done for the virtual member function as it can be accessed through a base class pointer. Does this mean that virtual member functions will be instantiated as soon as the template class is instantiated? If not, when?
推荐答案
14.7.1/9
in C++03:
实现不应隐式实例化不需要实例化的函数模板、成员模板、非虚拟成员函数、成员类或类模板的静态数据成员.如果虚拟成员函数不会被实例化,则实现是否隐式实例化类模板的虚拟成员函数是未指定的.
An implementation shall not implicitly instantiate a function template, a member template, a non-virtual member function, a member class or a static data member of a class template that does not require instantiation. It is unspecified whether or not an implementation implicitly instantiates a virtual member function of a class template if the virtual member function would not otherwise be instantiated.
这篇关于模板类的虚成员函数什么时候实例化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!