It can't, because with that system there's no guarantee that a Pet has an owner.
You could have an ownerless pet by doing this:
1 2 3 4 5
int main()
{
PetOwner::Pet ownerlesspet;
ownerlesspet.ownerName(); // <- ?? Who is the owner?
Nesting a class doesn't imply ownership, it just narrows the namespace that the class is in (ie: Pet is now in the PetOwner namespace instead of the global namespace).
If you want a Pet to have a trackable owner, you'll need to pair them up somehow:
1 2 3 4 5 6 7 8 9 10 11
class PetOwner
{
//...
Pet pet; // <- the pet owned by this owner
};
class Pet
{
//...
PetOwner* owner; // <- pointer to the owner that owns this pet
};