gpt4 book ai didi

c++ - result_of 对我不起作用

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:38:46 25 4
gpt4 key购买 nike

#include <type_traits>
using namespace std;

struct asd{
void f();
};

int f();

typedef typename result_of<decltype(f)>::type result_free;
typedef typename result_of<decltype(&asd::f)>::type result_mem;

两个 typedef 都报错

In file included from ../main.cpp:1:0:
/usr/include/c++/4.6/type_traits: In instantiation of ‘std::_Result_of_impl<false, false, int>’:
/usr/include/c++/4.6/type_traits:1215:12: instantiated from ‘std::result_of<int()>’
../main.cpp:10:41: instantiated from here
/usr/include/c++/4.6/type_traits:1192:9: error: ‘std::declval [with _Tp = int, typename std::add_rvalue_reference<_Tp>::type = int&&]()’ cannot be used as a function
../main.cpp:10:43: error: invalid combination of multiple type-specifiers
../main.cpp:10:59: error: invalid type in declaration before ‘;’ token
../main.cpp:11:49: error: ‘type’ in ‘struct std::result_of<void (asd::*)()>’ does not name a type
../main.cpp:11:64: error: invalid type in declaration before ‘;’ token

最佳答案

result_of 是 result_of<Fn(ArgTypes...)> ,不只是 result_of<Fn> ;

尝试

typedef typename result_of<decltype(&f)()>::type result_free;
typedef typename result_of<decltype(&asd::f)(asd)>::type result_mem;

(适用于 gcc 4.6.2)

关于c++ - result_of 对我不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9129575/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com