#include<iostream>
class Visitor;
class Animal{
public:
virtual void accpt(Visitor& visitor)=0;
}
class Dog:public Animal{
public:
void show(){
std::cout<<i am dog<<std::endl;
}
void accpt(Visitor& visitor) override{
visitor.visitDog(*this);
}
}
class Cat:public Animal{
public:
void show(){
std::cout<<i am cat<<std::endl;
}
void accpt(Visitor& visitor) override{
visitor.visitCat(*this);
}
}
class Visitor{
public:
virtual void visitDog(Dog &dog)=0;
virtual void visitCat(Cat &cat)=0;
}
class Beast:public Visitor{
public:
void visitDog(Dog &dog){
dog.show();
}
void visitCat(Cat &cat){
cat.show();
}
}
Dog dog;
Cat cat;
Beast beast;
dog.accpt(beast);
cat.accpt(beast);