我试图获取一个 auto
函数的返回类型。这个代码可以正常工作:
auto foo(int bar)
{
return 0;
}
typedef std::result_of<decltype(foo)> foo_t;
好的,那么接下来就是:获取类作用域中 static auto
函数的返回类型。这里有一个同样适用的方法:
struct Foo
{
static auto foo(int bar)
{
return 0;
}
};
typedef std::result_of<decltype(Foo::foo)> foo_t;
但是这不起作用:
struct Foo
{
static auto foo(int bar)
{
return 0;
}
typedef std::result_of<decltype(Foo::foo)> foo_t;
};
GCC 报错: "error: use of 'static auto Foo::foo(int)' before deduction of 'auto'", Clang 报错: "function 'foo' with deduced return type cannot be used before it is defined"。为什么?
std::result_of<decltype(&foo)(int)>::type
,对吗? - O'Neil