You define a local variable of type A in the constructor of B, and return a pointer to that local variable. Using that pointer results in undefined behavior, because the object it points to no longer exists.
Solutions to the problem might include:
allocate the A object on the heap. But then try to wrap it in an appropriate smart pointer rather than a simple pointer.
Have a member of type A in B and return the member's address
Have an object of type A with static storage duration, like the pointer itself.
The decision between these three depends heavily on the context of your problem which is not deducible from your question.
One more thing. Nested classes are those classes that are defined in scope of another class. There are no nested classes in your example.