我知道,模板类的普通成员函数,只要第一次使用,就会被实例化。但这不能为虚拟成员函数完成,因为它可以通过基类指针访问。这是否意味着只要模板类被实例化,虚成员函数就会被实例化?如果不是,什么时候?
最佳答案
14.7.1/9
在 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.
关于c++ - 模板类的虚成员函数什么时候实例化?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3483932/