I have a hierarchy as follows:
class Element{ public : virtual void Accept(Visitor&) = 0
protected : Element(); int num;
};
class ElementA : public Element{
public : ElementA();
void Accept(Visitor& v) {v.Visit(this};}
};
class ElementB : public Element{
public : ElementB();
void Accept(Visitor& v) {v.Visit(this};}
class Visitor{
public: void Visit(ElementA*);
void Visit(ElementB*);
};
EDIT: It is required to add the method int getNum() to the hierarchy that would provide the value of num. However, this will need that the entire hierarchy be compiled again and we are not allowed to do that. So we have to change the design of the hierarchy in a way so that the recompilation of the hierarchy is not needed.