Consider the following code:
struct A{
private:
struct B{};
public:
B make() const{return B{};}
};
int main(){
A a;
auto b1 = a.make(); (void)b1;
// A::B b2 = a.make(); (void)b2; // compile error: B is a private class
}
What is the logic behind being able to compile b1
line while the second b2
line? After all auto
is supposed equivalent to replace the name of the class.
If it is what I think, this shows that auto
is not simply syntax sugar.
auto
on private classes can be used force the user not know about certain types but still be able to use instance of them! (and this was not possible in C++98?)
Am I mistaken in this interpretation?