For example
struct A
{
auto count() -> decltype(m_count) { return m_count; }
int m_count;
};
The above gets compilation error because m_count in decltype is not recognized. How to work around it? auto return and get the type from m_count must be used.
The code compiles when the order is changed
struct A
{
int m_count;
auto count() -> decltype(m_count) { return m_count; }
};
but how do I get the first case to work?
In C++, you can't use a name that hasn't been introduced (declared) in a declaration, including in a
decltypefor a trailing return type. So you must reorder your declarations :