Nested classes in C++ are essentially static nested class.
Non-static ones like in Java would be a bit harder to emulate in C++, because there is no compiler magic to automatically provide the context of the outer class. You would have to work around the issue by storing a reference to the outer class in the inner class, initialising it in the constructor of the inner class, and accessing members of the outer class explicitly via the reference.
```
#include<iostream>
using namespace std;
class A {
public:
class B {
private:
int num;
public:
void getdata(int n) { num = n; }
void putdata() { cout<<"The number is "<<num<<endl; }
};
void f() {
B obj;
obj.getdata(9);
obj.putdata();
}
};
int main() {
A a;
a.f();
A::B b;
b.getdata(9);
b.putdata();
return 0;
}
```
Output:
```
The number is 9
The number is 9
```