Sign in to follow this  

Defining nested class separately

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

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


Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this