Let\'s define a class inside a free function, and access it outside:
#include
auto myFunc(){
class MyType{public: int i = 0; int j = 1;}
The standard doesn't say anything about this specifically, except that — as you've already pointed out — it's the name that has a scope, not the type. Use of auto
bypasses the type's name, giving you a way to get at the type regardless of the name's scope.
It's kind of similar to how making a nested class private doesn't mean you can't use instances of it, only that you can't name it outside of the encapsulating class's scope.
I don't see how you'd "prevent" it, nor why you'd want to.