• 14
• 15
• 10
• 10
• 9

# Defining nested class separately

This topic is 4193 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Is it possible to define a subclass outside the main class? Something like: class A { class B; }; class A::B { };

##### Share on other sites
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();}