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