gpt4 book ai didi

c++ - 如何实现 Cloneable 类?

转载 作者:行者123 更新时间:2023-11-30 03:40:08 24 4
gpt4 key购买 nike

<分区>

class Cloneable
{
public:
virtual Cloneable* clone() const = 0; //return copy of itself
virtual ~Cloneable() {}
};

class A
{
public:
A(const A& a);
~A();

private:
Cloneable* b;
Cloneable* c;
std::string* s;
};

A::~A()
{
delete b;
delete c;
delete s;
}

请帮助我理解可克隆模式。我不明白如何实现类 A 的构造函数、复制构造函数以及如何使用它们?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com