incomplete type error

后端 未结 1 1773
感情败类
感情败类 2020-12-19 16:51

Im trying to make class A a friend of class B.

class B;

class A{
public:
void show(const B&); // ##1## but this one works fine  
B ob;// error incomplet         


        
相关标签:
1条回答
  • 2020-12-19 17:19

    No, that's a forward declaration and does not define a full type. You'll need to have a full definition of B before A, if you want to keep the member as an object and not pointer.

    One of the reason for this is that the size of the class B must be known to A, since A's size depends on B.

    I suggest you #include "B.h" in A.h.

    EDIT: clarification:

    struct A;
    
    struct B
    {
       A foo();
       void foo(A);
       void foo(A&);
       void foo(A*);
    
       A* _a;
       A& __a;
       A a;  // <--- only error here
    };
    
    0 讨论(0)
提交回复
热议问题