C++ circular dependency - namespace vs struct

Posted by Dead or Alive on Stack Overflow See other posts from Stack Overflow or by Dead or Alive
Published on 2011-02-08T21:55:27Z Indexed on 2011/02/09 7:25 UTC
Read the original article Hit count: 156

Filed under:
|

Please educate me. Why does this compile:

struct compiles
{
    struct A;
    struct B
    {
        B(const A &a) : member(a.member) { }
        int member;
    };
    struct A
    {
        A(const B &b) : member(b.member) { }
        int member;
    };
};

while this does not:

namespace doesnt
{
    struct A;
    struct B
    {
        B(const A &a) : member(a.member) { }
        int member;
    };
    struct A
    {
        A(const B &b) : member(b.member) { }
        int member;
    };
}

(in MSVC 9.0)

© Stack Overflow or respective owner

Related posts about c++

Related posts about namespaces