1
// 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
@Oberon:更新的主要問題 –
OBFactory有多少個'func'?如果不止一個,那麼對於哪個選擇是不明確的。如果可能的話,你能否提供一個最小*完整*程序例如'ideone'? –