如何像未定义的函数一样传递一个未定义的方法 [英] How Can I Pass an Undefined Method Like an Undefined Function

查看:151
本文介绍了如何像未定义的函数一样传递一个未定义的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

鉴于我传递了未定义的函数:

  void foo(char,short) ; 

了解如何通过调用 decltype(m(foo))获取类型 tuple 这个功能:

  template< typename Ret,typename ... Args> 
tuple< Args ...>米(退役(参数...));

我现在想传递一个未定义的方法:

  struct bar {void foo(char,short); }; 

我尝试重写 m / p>

 模板< typename Ret,typename C,typename ... Args> 
tuple< Args ...>米(退役(C :: *)(参数数量...));

但是当我尝试使用 decltype(m(bar :: foo))类似地调用这个我收到错误:


无效使用非静态成员函数 void bar :: foo(char,short int)


我如何像函数一样传递这种方法?

解决方案

如果您只想使用 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 calling decltype(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:

invalid use of non-static member function void bar::foo(char, short int)

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))

这篇关于如何像未定义的函数一样传递一个未定义的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆