In the inheriting situation, you can treat the derived class like its base class. That is, you can keep a collection of base class references around and call their methods without needing to know whether the actual objects are of any derived type, and if yes which. This an important semantic concept.
In the member class case, the inner class is just an implementation detail of the outer class and not even visible to the consumer. Even it it were visible, it would just be one feature of the foo
class. You can see that the two situations are semantically very different, and you have to pick the one which represents your actual data model most accurately.
Technically, the derived class probably weighs a tiny bit heavier because of various virtual function calls, but the details depend on your language and the concrete situation.