In this question it was discussed why exposing a private type with auto
:
#include <iostream>
using namespace std;
class Base {
class PrivateClass {
public:
void bar() { cout << "PrivateClass" << endl; }
};
public:
PrivateClass foo() {
PrivateClass a;
return a;
}
};
int main() {
Base b;
auto p = b.foo();
p.bar();
return 0;
}
is perfectly fine by the C++11 standard. What I still don't get is how this idiom may be useful in a real application. Are there problems where this idiom can be effectively used, or it should be considered as a "curious" side-effect of the keyword?