本文介绍了如何像未定义的函数一样传递一个未定义的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
鉴于我传递了未定义的函数:
void foo(char,short) ;
我我收到错误:
我如何像函数一样传递这种方法?
解决方案
如果您只想使用 decltype
,您只需要额外的一个&
:
decltype(m(& bar :: foo))
pre>
Given that I was passing the undefined function:
void foo(char, short);
I learned how to obtain the type
tuple
of the arguments by callingdecltype(m(foo))
with this function:template <typename Ret, typename... Args> tuple<Args...> m(Ret(Args...));
I would now like to pass an undefined method:
struct bar { void foo(char, short); };
I had tried rewriting
m
like:template <typename Ret, typename C, typename... Args> tuple<Args...> m(Ret(C::*)(Args...));
But when I try to call this similarly with
decltype(m(bar::foo))
I get the error:How can I pass this method like I did for the function?
解决方案If you only want to use
decltype
on it, you simply need an extra&
:decltype(m(&bar::foo))
这篇关于如何像未定义的函数一样传递一个未定义的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!