简体   繁体   English

如何了解有效C ++中的“虚拟构造函数的实现”

[英]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.

相关问题 如何在 C++ 中使用 gtest 测试具有不同构造函数的多个接口实现? - How to test several interface implementations with different constructors with gtest in C++? doxygen c ++虚拟函数和实现 - doxygen c++ virtual functions and implementations C++ 错误:试图理解类和构造函数 - C++ error: trying to understand Classes and Constructors 使用C ++在虚拟继承期间调用构造函数 - Invoking constructors during virtual inheritance with C++ 不同的编译器的C ++虚拟继承实现不兼容吗? - Are different compilers' C++ virtual inheritance implementations incompatible? 在C ++中的虚拟基类的两种实现之间共享方法 - Sharing methods between two implementations of a virtual base class in C++ C ++语言设计:子代调用所有虚拟祖先构造函数 - C++ language design: child calls all virtual ancestor constructors C ++构造函数:为什么这个虚函数调用不安全? - C++ constructors: why is this virtual function call not safe? 有效的C ++仍然有效吗? - Is effective C++ still effective? C ++可以将用作虚拟基础的类具有带参数的构造函数吗? - c++ can classes used as virtual bases have constructors with parameters?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM