Consider the following code:
class A
{
private:
class B {};
public:
B f();
};
A a;
A::B g()
{
return a.f();
}
The compiler rejects this - g cannot return A::B because A::B is private.
But suppose I now use decltype to specify the return value of g:
class A
{
private:
class B {};
public:
B f();
};
A a;
decltype(a.f()) g()
{
return a.f();
}
All of a sudden it compiles fine (with g++ >= 4.4).
So I've basically used decltype to get around an access specifier in a way I would not have been able to in C++98.
Is this intentional? Is this good practice?