c++ - How to make classes using each other -


class a; class b;  class {    public:     a(b * b) : b(b)     {            b->foo(this);     }    private:     b * b; };    class b {    public:     void foo(a *)     {}   }; 

compiling code gives me

incomplete-type.hpp: in constructor ‘a::a(b*)’: incomplete-type.hpp:9:4: error: invalid use of incomplete type ‘class b’    b->foo(this);     ^~ 

but need classes use each other via pointers. how can this?

move function definitions use other type below, both types complete.

class a; class b;  class {    public:     a(b * b); private:     b * b; };    class b {    public:     void foo(a *)     {}   };  inline a::a(b * b) : b(b) {     b->foo(this); } 

Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -