虚拟构造函数 - 实现虚拟函数clone()
:
class X {
public:
virtual X* clone() {
return new X(*this);
}
};
与原型(prototype)设计模式的概念相同吗?
最佳答案
... mean the same concept as the Prototype design pattern?
不,事实并非如此。 可克隆接口(interface)只是 Prototype Design Pattern 实现的一部分.
原型(prototype)的要点是有一个 Factory保存原型(prototype)实例的实例,并知道使用哪个实例作为克隆源来创建新实例。
关于c++ - "Prototype pattern"和 "Virtual constructor"是相同的模式吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56349195/