[英]How to understand “implementations of virtual constructors” in Effective C++
In Effective C++ 3rd, Item 31, p146-p147, it says 在有效的C ++ 3rd,第31项,p146-p147中,它说
That all happens behind the scenes inside the files containing the implementations of virtual constructors.
这一切都发生在包含虚拟构造函数实现的文件内部的幕后。
I'm not sure how to understand virtual constructors in this sentencen. 我不确定在这句话中如何理解虚拟构造函数。
As far as I know, there is no virutal constructor in C++. 据我所知,C ++中没有强大的构造函数。
So, is this statement a mistake in Effective C++? 那么,此语句在有效C ++中是否是一个错误?
Or, does this virtual constructors refers to other things? 或者,此虚拟构造函数是否引用其他内容?
As far as I know, there is no virutal constructor in C++.
据我所知,C ++中没有强大的构造函数。
Correct. 正确。
So, is this statement a mistake in Effective C++?
那么,此语句在有效C ++中是否是一个错误?
No. 没有。
Or, does this virtual constructors refers to other things?
或者,此虚拟构造函数是否引用其他内容?
It's just a common name for a design pattern which results in code that works like a "virtual constructor" would work, if it existed. 它只是设计模式的通用名称,如果存在,其结果将使代码的工作方式类似于“虚拟构造函数”。 Instead of saying " a mechanism which works as if the constructor was virtual, even though it technically isn't" , we simply say "virtual constructor" .
与其说“ 即使在技术上不是,也可以像构造函数是虚拟的那样工作的机制” ,我们只是说“虚拟构造函数” 。
Another common name for the same pattern is "factory method". 相同模式的另一个通用名称是“工厂方法”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.