Question

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();
};
Was it helpful?

Solution

This works for me:

struct A {
    class B;
    B fun();
    class B {
        friend B A::fun();
    };
};
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top