gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:25:45 25 4
gpt4 key购买 nike

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

最佳答案

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com