C++ using typedef shared_ptr<Class> Shared as a type of field - member of another class

202 views Asked by At

I have to classes, by exmaple class A and class B. Class A include B and B include A. Class A has typedef shared_ptr Shared, in class B I need to declare field-member type of A::Shared.

#include "B.h"
class A {
public:
    typedef shared_ptr<A> Shared;
};

#include "A.h"
class A;
class B {
public:
    A::Shared mA;
};

IDE says that can't resolve type Shared.

SOLVED Remove #include directive from both headers, and use forward declaration.

class B;
class A {
public:
    typedef shared_ptr<A> Shared;
};

class A;
class B {
public:
    A::Shared mA;
};
0

There are 0 answers