I am trying to use the decltype
keyword on an auto function:
struct Thing {
static auto foo() {
return 12;
}
using type_t =
Because for class definition, compiler will first determine all member names and types. Function body is analyzed after this is done.
That's why a class member function can call another member function declared after its own definition.
At the point compile is determining
using type_t = decltype(foo());
function foo()
's body has not yet been analyzed.
As a remedy, you can use
static auto foo() -> decltype(12) {
return 12;
}
NOTE:
This phenomenon is only for class. The following code outside a class will compile:
auto bar() { return 12; }
using t = decltype(bar());