Реализации на С++

Visitor

Общая реализация на языке С++

class Circle;
class Rectangle;

class Visitor
{
public:
    virtual ~Visitor() = default;
    virtual void visit(Circle& ref) = 0;
    virtual void visit(Rectangle& ref) = 0;
};
# include <iostream>
# include <memory>
# include <vector>

using namespace std;

int main()
{
    shared_ptr<Shape> figure = make_shared<Figure>(
        initializer_list<shared_ptr<Shape>>(
            { make_shared<Circle>(), make_shared<Rectangle>(), make_shared<Circle>() }
        )
    );
    shared_ptr<Visitor> visitor = make_shared<ConVisitor>();
    figure->accept(visitor);
}

Last updated

Was this helpful?