[Solved] Accessing members in same namespace in C++ [closed]


You can use forward declaration of your class second and use a pointer. Only the implementation must know the declaration of your class Second.

namespace A {
    class Second;  // Forward declaration
    class First
    {
    public:
        First();
    ~First();
    private:
        Second* s; // Pointer on a forward class
    };

    class Second
    {
    private:
        First f;
    };


    First::~First()
    {
        delete s;
    }

    First::First()
    {
        s = new Second();
    }

}

1

solved Accessing members in same namespace in C++ [closed]