2

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();
};
4

1 回答 1

3

This works for me:

struct A {
    class B;
    B fun();
    class B {
        friend B A::fun();
    };
};
于 2013-05-05T18:00:19.923 回答