原型模式
#include <memory> #include <iostream> class Prototype { public: Prototype() {} Prototype(const Prototype& p) { this->data = p.data; } virtual std::unique_ptr<Prototype> copy() { return std::make_unique<Prototype>(*this); } void show() { std::cout << "In Prototype show(). The data is " << data << std::endl; } void set(int data) { this->data = data; } private: int data = 0; }; int main(int argc, char* argv[]) { Prototype p; std::unique_ptr<Prototype> up = p.copy(); up->show(); return 1; }