The following code:
struct A
{
int f(int);
auto g(int x) -> decltype(f(x));
};
Fails to compile with the error:
erro
Seems to me that does not work because the decltype is outside of the method and A is at that moment an incomplete type (so you can't even do A().f(x)
).
But you should not really need that. Outside of the declaration of A this will work as expected, in A you should know the return type of the function that you declared a few lines above. Or you could just write:
struct A {
typedef int ret_type;
ret_type f(int x);
ret_type g(int x);
};
This even works with plain c++03.