Defining nested class separately

Started by
1 comment, last by snooty 17 years, 6 months ago
Is it possible to define a subclass outside the main class? Something like: class A { class B; }; class A::B { };
Advertisement
The fastest way to see if this would work is to try it for yourself.

But yes, you can do this as long as you don't try to use the incomplete type improperly before you fully define it...

class A{    class B;    B *b;public:    int foo();};class A::B{public:      int x, y;};int A::foo(){    b = new B(); // stupid example, whatever...    return b->x * b->y;}int main( int arg, char **argv ){    A a;    int x = a.foo();}
Thank you. :)

This topic is closed to new replies.

Advertisement