First of all, there is nothing wrong to do something this way. Many people like to put one class on the title, in general. If you donโt like looking at a lot of headings, you can organize them by catalog or filter of the project tree, etc.
This is all a matter of style. As long as the functionality is not touched, the best option is the function of this ridiculous feeling that you have, and the same for people supporting your code in the future. Maybe this answer may make this ridiculous feeling go to you, or maybe not.
Secondly, it is very dependent on the use of each class. If the Foo and Bar classes are small, they can be placed in the header containing the encapsulating class. Perhaps add a forward declaration for the parent class and end the declaration at the bottom of the heading. Bonus points, if they are all connected (for example, FooConnection is a subclass of Foo ), as this reduces the declaration space.
If they are relatively small classes, there can be no harm in declaring the Foo and Bar classes in the definition of their base class. Then there is no FooConnection - actually a Connection::FooConnection . In this case, Connection not only defines the base for FooConnection , it has its own definition . This means that every time you use FooConnection in your code, you think in the context of Connection . I rarely do this myself, primarily because I donโt like typing Connection:: all the time, but also because there are so few cases where I use only a class in one context.
If the encapsulated classes are protected or private , then they are used only by the parent class itself (and friend classes and, possibly, subclasses that you have). Then, since the restricted context is set, and if class declarations are small (<50 or 100 lines), you can declare FooConnection and BarConnection within Connection and maintain readability.
Bonus Point: If you end up declaring classes inside classes, you can use namespace splitting. I do not know the use of these classes, but I assume that FooConnection not the connection itself, but Foo , which belongs to Collection . So, you can declare a class Foo and Bar for each of Widget , Connection and Config .