【发布时间】:2013-09-29 08:25:53
【问题描述】:
// This compiles and runs properly
using MemPtr = Entity&(OBFactory::*)(const Vec2i&, float);
void test(MemPtr mptr, const Vec2i& p, float d)
{
(getFactory().*mptr)(p, d);
}
// "no matching function for call to `test`,
// failed candidate template argument deduction"
template<typename... A> using MemPtr = Entity&(OBFactory::*)(A...);
template<typename... A> void test(MemPtr<A...> mptr, const Vec2i& p, float d)
{
(getFactory().*mptr)(p, d);
}
...
// I call both versions with
test(&OBFactory::func, Vec2i{0, 0}, 0.f);
为什么可变参数模板版本不起作用?我错过了一些转发吗?
【问题讨论】:
-
第二版
test()怎么称呼? -
@Oberon:更新了主要问题
-
OBFactory有多少个func?如果不止一个,那么对于选择哪个就存在歧义。如果可能,您能否提供一个最小的完整程序,例如ideone?
标签: c++ pointers c++11 variadic-templates pointer-to-member