QtDesignPatterns/prototypepattern/interface.h

41 lines
621 B
C
Raw Normal View History

2024-02-06 17:21:37 +08:00
#include <string>
#include <iostream>
using namespace std;
class Shape
{
public:
Shape()
{
cout << "create Shape" << endl;
}
virtual ~Shape(){}
virtual Shape *clone() = 0;
virtual void test() = 0;
};
class Circle: public Shape
{
public:
Circle(string type) : type(type)
{
cout << "create Circle" << endl;
}
~Circle(){}
Circle(const Circle& circle)
{
this->type = circle.type;
}
Shape *clone()
{
return new Circle(*this);
}
void test()
{
cout << "type: " << type << endl;
}
private:
string type;
};