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 now I use decltype to indicate the return value of g:
class A
{
private:
class B {};
public:
B f();
};
A a;
decltype(a.f()) g()
{
return a.f();
}
Suddenly it compiles fine (with g ++> = 4.4).
So I basically used decltype to get around the access specifier, whatever I was in C ++ 98.
Is it intentional? Is this a good practice?
source
share