質問

how can I implement such an idea in C++ without getting into "invalid use of incomplete type" trouble?

class A {
    /*(...) some fields and methods here. */
    class B {
        /*(...) some fields and methods here. */
        friend B A::fun();
    };
    B fun();
};
役に立ちましたか?

解決

This works for me:

struct A {
    class B;
    B fun();
    class B {
        friend B A::fun();
    };
};
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top