The private one is probably more useful and effectively provides an encapsulated private resource class for the containing class to use.
The public one could be useful for organisational purposes.
If you define class C separately, there is a risk of name clashes.
If you need to define a class that is only going to be used to serve another class, then it may be appropriate to embed it inside the class it serves.
Nesting allows us to hide the nested class.
NestedClass does not contain the attributes of OuterClass, they are independent in that sense, but it can access those attributes.
class A {
private:
int a;
class B {
private:
int b;
public:
B(int bb) { b = bb; }
};
public:
A(int aa) { a = aa; }
class C {
private:
int c;
public:
C(int cc) { c = cc; }
};
};
This isn’t just for nested classes.