Circular dependencies of declarations

前端 未结 6 1229
眼角桃花
眼角桃花 2021-01-19 05:02

I am trying to implement example of visitor pattern, but I have trouble with circular dependecies of declarations of classes. When I do forward declaration of class Visitor,

6条回答
  •  一个人的身影
    2021-01-19 06:00

    Alexy gave one part of the answer already.

    However, if you're not going to implement accept for Land then you need:

    class Land {
      public:
        virtual void accept(const Visitor *v)= NULL;
    };
    

提交回复
热议问题