c++ - 模板类的虚成员函数什么时候实例化?

标签 c++ templates

我知道,模板类的普通成员函数,只要第一次使用,就会被实例化。但这不能为虚拟成员函数完成,因为它可以通过基类指针访问。这是否意味着只要模板类被实例化,虚成员函数就会被实例化?如果不是,什么时候?

最佳答案

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/

相关文章:

templates - 无法从 sitecore 中删除模板。出现错误 "The template is used by at least one item"?

javascript - 将 someVar +'a string' 传递给 Handlebars.js 助手?

c++ - 移动构造函数调用基类移动构造函数

c++ - 如何制作抽象模板类的 vector

c++ - SDL 击键增量计数器

c++ - 什么是?和 : mean in C++?

c++ - 如何使用 sprintf 将 uint_64 类型的数组附加到 char 数组?

c++ - 在运行时之前调用类型未知的模板函数

c++ - 画一个里面有数字的实心圆

C++ 创建和使用类