我们可以在C ++中创建一个虚拟的类拷贝构造函数 [英] Can we make a class copy constructor virtual in C++
本文介绍了我们可以在C ++中创建一个虚拟的类拷贝构造函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我们可以在C ++中创建一个虚拟的类复制构造函数吗?如何使用?
Can we make a class copy constructor virtual in C++? How to use?
推荐答案
不能,构造函数不能是虚拟的。
No you can't, constructors can't be virtual.
C ++ 03 - 12.1构造函数
C++03 - 12.1 Constructors
4)构造函数不应
virtual
(10.3)或static
(9.4)。 [...]
4) A constructor shall not be
virtual
(10.3) orstatic
(9.4). [...]
如果你需要这样的东西,你可以查找虚拟构造函数idiom 此处。
If you need something like this, you can look up the virtual constructor idiom here.
这篇关于我们可以在C ++中创建一个虚拟的类拷贝构造函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文