The impact of virtual on the use of member of class template

送分小仙女□ 提交于 2019-12-03 02:34:02

A quick look at 3.2 [basic.def.odr] yields:

3/ [...] A virtual member function is odr-used if it is not pure. [...]

And I also found at 14.7.1 [temp.inst]:

10/ 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. (emphasis mine)

So... I would say it is likely that a virtual method will always be instantiated.

In pragmatic terms, I would expect a compiler to instantiate the virtual table of a template class when it instantiates the class; and thus immediately instantiate all virtual member functions of this class (so it can references those from the virtual table).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!