我有一个函数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.
}
这不会编译。错误(通过clang使用C++ 1z)是:
/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) {}
为什么“int”替换失败?
我可以编译成功,如果我明确地写里面FOO()类型:
template <typename ... vARGS>
void foo(void(*funcptr)(vARGS ... V_args)) {}
但我不能获得初始(“使用”)版本,即使明确指定模板参数,并使用工作预铸TFuncType<int>
的说法,即:
int main() {
TF_call<int> fptr = &bar; // This line is OK.
foo<int>(fptr);
}
有谁知道这是怎么回事吗?
使用typedef'd(“using”)variadics和/或函数指针我有什么奇怪吗?
适用于GCC,我想不出任何规则这个代码打破了,所以我要去用一个铿锵虫。 –
好吧,我会离开它一个小时左右,然后提交一个错误报告,如果没有进一步的评论。谢谢。 – xaxazak
编译器版本? – Yakk