Реализации на С++
Prototype
Общая реализация на языке С++
class Car
{
public:
virtual ~Car() = default;
virtual unique_ptr<Car> clone() = 0;
};
class Sedan : public Car
{
public:
Sedan()
{
cout << "Calling the default constructor;" << endl;
}
Sedan(const Sedan& car)
{
cout << "Calling the Copy constructor;" << endl;
}
~Sedan() override
{
cout << "Calling the destructor;" << endl;
}
unique_ptr<Car> clone() override
{
return make_unique<Sedan>(*this);
}
};
# include <iostream>
# include <memory>
using namespace std;
int main()
{
shared_ptr<Car> sedan = make_shared<Sedan>();
User{}.use(sedan);
}
Last updated
Was this helpful?