I made this simple class, which still is playing with my mind:
class A {
private:
class B {};
public:
B getB() {
return B();
};
};
As of C++03, this class compiles fine, but there is just no nice looking way to assign the result of getB()
to an lvalue, in the sense that:
A::B b = A().getB();
Does not compile.
I got it by using an intermediate template, in this fashion:
template <typename T>
struct HideType {
typedef T type;
};
HideType<A::B>::type b = A().getB();
But this looks just terrible, for this simple task of getting an A::B lvalue variable.
This is not true anymore as of C++11, or at least it is not with gcc. This code is still not valid:
A::B b = A().getB();
But this is valid:
auto b = A().getB();
Is there a loophole in the standard respect to this?