【发布时间】:2017-02-06 03:53:09
【问题描述】:
我正在制作这样的方法指针包装器:
template<typename OBJECT, typename... ARGS>
method_wrapper<ARGS...> _getWrapper(OBJECT* object, void (OBJECT::*method)(ARGS...))
{
//irrelevant
}
问题就在_getWrapper的调用处:
class TestClass
{
void TestMethod(int a, float b, bool c)
{
std::cout<<a<<std::endl;
std::cout<<b<<std::endl;
std::cout<<c<<std::endl;
}
};
int main()
{
TestClass testObj;
method_wrapper<int, float, bool> wrap = _getWrapper<int, float, bool>(&testObj, TestClass::TestMethod);
wrap.callInternal(1000, 3.14, true);
//...
system("pause");
return 0;
}
无论我以何种方式尝试在 _getWrapper 中传递参数,它仍然告诉我:
没有重载函数的实例与参数列表匹配
OBJECT::*method 不直接匹配 TestClass::TestMethod 吗?我也试过&TestClass::TestMethod,也不匹配。
【问题讨论】:
标签: c++ templates variadic-templates member-function-pointers