How Can I Pass an Undefined Method Like an Undefined Function

≡放荡痞女 提交于 2019-12-23 02:04:07

问题


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?


回答1:


If you only want to use decltype on it, you simply need an extra &:

decltype(m(&bar::foo))


来源:https://stackoverflow.com/questions/38482805/how-can-i-pass-an-undefined-method-like-an-undefined-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!