我正在学习如何获取重载函数vstype
的返回值。 test()
test(double)
我从SO answer (by chris)修改了代码。
#include <type_traits>
#include <utility>
int test();
double test(double x);
template<typename... Ts>
using TestType = decltype(test(std::declval<Ts>()...))(Ts...);
int main() {
std::result_of< TestType<double> >::type n = 0;
//^ ### compile error ###
using doubleDat = std::result_of< TestType<double> >::type ;
doubleDat n=0;
}
我得到一个编译错误。
错误:“std::result_of”中没有名为“type”的类型
我认为:-
TestType<...>
是“可变参数模板”。
用我自己的话来说,它就像一个包含任意数量参数的压缩缩写。TestType<double>
函数的idtest(double)
。 _std::result_of<TestType<double>>::type
是的返回类型test(double)
。
doubleDat
应该是double
。
问题:为什么它不编译?如何解决?
我已经阅读了这些:-
- 重载成员函数的 decltype - 没有关于
std::result_of
- c++:错误:'class std::result_of<void (*(std::unordered_map - 与线程相关的问题,而不是
std::result_of
线索:经过长时间的搜索,我闻到我的代码遭受“最令人烦恼的解析”的微弱气味。