it either tells me I need an object [...]
Think about that. Because that's exactly what the problem is here.
If you instantiate an A
, you don't also get a B
. A nested class isn't a member variable of the enclosing class. It's really just another way to change the namespace of a class.
So, you need an instance of B
. Perhaps a member of A
?
class A
{
class B
{
public:
int x;
} mB;
public:
void printX() { std::cout << mB.x; }
};