当前位置: 首页> 教育> 就业 > 建网站作业_福建搜索引擎推广方法_推广优化方案_收录网站是什么意思

建网站作业_福建搜索引擎推广方法_推广优化方案_收录网站是什么意思

时间:2025/7/11 23:28:52来源:https://blog.csdn.net/Black_Silencer/article/details/144382368 浏览次数:0次
建网站作业_福建搜索引擎推广方法_推广优化方案_收录网站是什么意思

Prototype Pattern

Intent: Use prototype instances to specify the type of objects to be created, and create new objects by copying these prototypes.
Main issue addressed: Dynamically create and delete prototypes at runtime.

used in qt:

QTableWidgetItem *QTableWidgetItem::clone() const

some codes:

#include <iostream>
#include <memory>  // For std::unique_ptr
#include <string>// Prototype class templatetemplate <typename T>
class Prototype {
public:virtual ~Prototype() = default;// Virtual method to clone the objectvirtual std::unique_ptr<T> clone() const = 0;// A method to display object information (can be customized)virtual void display() const = 0;
};// ConcretePrototype class templateclass ConcretePrototype : public Prototype<ConcretePrototype> {
private:std::string name;public:explicit ConcretePrototype(const std::string& name) : name(name) {}// Override the clone function to return a copy of the current objectstd::unique_ptr<ConcretePrototype> clone() const override {return std::make_unique<ConcretePrototype>(*this); // Create a new object as a copy of the current one}void display() const override {std::cout << "ConcretePrototype name: " << name << std::endl;}
};
int main() {// Create an original prototype objectauto original = std::make_unique<ConcretePrototype>("Original");// Display the original objectoriginal->display();// Clone the objectauto clone1 = original->clone();clone1->display(); // Display the cloned object// Clone againauto clone2 = original->clone();clone2->display(); // Display another cloned objectreturn 0;
}
关键字:建网站作业_福建搜索引擎推广方法_推广优化方案_收录网站是什么意思

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: