为什么构造函数不能是虚拟的 [英] why cant a constructor be virtual

查看:76
本文介绍了为什么构造函数不能是虚拟的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么构造函数不能在C ++中虚拟化?

Why cant a constructor be virtual in C++?

推荐答案

构造函数不能是虚拟的,因为在调用构造函数时虚拟表将不可用在内存中.因此,我们不能有一个虚拟的构造函数.
http://www.daniweb.com/software-development/cpp/threads/137286 [
A constructor cannot be virtual because at the time when the constructor is invoked the virtual table would not be available in the memory. Hence we cannot have a virtual constructor.
http://www.daniweb.com/software-development/cpp/threads/137286[^]


因为没有一个继承的类可以实现具有相同名称的方法,例如,参见竞争对手" [ ^ ].
Because no one of the inheriting classes could implement a method having the same name, see, for instance, "The Competitors"[^].


以下是该人本人的回答- ^ ]
Here is the answer from the man himself - http://www2.research.att.com/~bs/bs_faq2.html#virtual-ctor[^]


这篇关于为什么构造函数不能是虚拟的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆