加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 实例化模板类的虚拟成员函数?

发布时间:2020-12-16 09:29:15 所属栏目:百科 来源:网络整理
导读:我知道模板类的普通成员函数将在第一次使用时被实例化.但是这不能用于虚拟成员函数,因为它可以通过基类指针访问.这意味着只要实例化tmeplate类,就会实例化虚拟成员函数?如果不是的话? 解决方法 C 03中的14.7.1 / 9: An implementation shall not implicit
我知道模板类的普通成员函数将在第一次使用时被实例化.但是这不能用于虚拟成员函数,因为它可以通过基类指针访问.这意味着只要实例化tmeplate类,就会实例化虚拟成员函数?如果不是的话?

解决方法

C 03中的14.7.1 / 9:

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.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读