error: member access into incomplete type : forward declaration of

前端 未结 2 669
清歌不尽
清歌不尽 2020-12-03 02:43

I have two classes in the same .cpp file:

// forward
class B;

class A {       
   void doSomething(B * b) {
      b->add();
   }
};

class B {
   void a         


        
2条回答
  •  再見小時候
    2020-12-03 03:11

    Move doSomething definition outside of its class declaration and after B and also make add accessible to A by public-ing it or friend-ing it.

    class B;
    
    class A
    {
        void doSomething(B * b);
    };
    
    class B
    {
    public:
        void add() {}
    };
    
    void A::doSomething(B * b)
    {
        b->add();
    }
    

提交回复
热议问题