我有一个函数foo,它使用可变参数函数指针作为其参数.
我想在函数声明之前使用"using"来定义参数的类型.
template <typename ... vARGS>
using TFuncType = void(*)(vARGS ... V_args);
template <typename ... vARGS>
void foo(TFuncType<vARGS ...> funcptr) {}
void bar(int i) {}
int main() {
foo(&bar); // This line fails to compile.
}
Run Code Online (Sandbox Code Playgroud)
这不编译.错误(通过使用c ++ 1z的clang)是:
/make/proj/test/variadic-funcparam-deduce2.cpp:39:5: error: no matching function for call to 'foo'
foo(&bar);
^~~
/make/proj/test/variadic-funcparam-deduce2.cpp:33:36: note: candidate template ignored: substitution failure [with vARGS = int]
template <typename ... vARGS> void foo(TFuncType<vARGS ...> funcptr) {}
Run Code Online (Sandbox Code Playgroud)
为什么"int"替换失败了?
如果我在foo()中明确写出类型,我可以成功编译:
template <typename ... vARGS>
void foo(void(*funcptr)(vARGS …Run Code Online (Sandbox Code Playgroud)