I got error compiling below code.
struct B{
double operator()(){
return 1.0;
}
};
struct A {
auto func() -> decltype(b())
{
return b();
}
B b;
};
However, if I reorganize the A
, it compiles.
gcc 4.8 said that 'b' was not declared in this scope.
struct A {
B b;
auto func() -> decltype(b())
{
return b();
}
};
So, what is wrong with the first??
The definition of the class
is processed it two passes: first the member declarations are collected, including function signatures, and then the bodies of definitions are parsed.
The function body therefore has access to all member declarations, including subsequent ones, but the function prototype only sees preceding declarations.