我对模板还不熟悉,不太明白为什么这个不起作用。我期望向量会使用这些值进行构建。
main.cpp
template <typename ...T>
void int_printf(T ...args)
{
std::vector<T> vec = {args...};
for(auto& v:vec)
{
std::cout << v << std::endl;
}
}
int main()
{
int_printf(1,2,3,4);
return 0;
}
预期结果
1
2
3
4
msvc编译器错误(翻译完成)
src/main.cpp(35): error C3520: 'T': the parameter pack must be expanded in this context
src/main.cpp(37): error C3536: '<begin>$L0': can't be used before initialization
src/main.cpp(37): error C3536: '<end>$L0': can't be used before initialization
src/main.cpp(37): error C2100: invalid redirection
int_printf(3, nullptr, -9e134, "hello", main);
的类型是什么?vec
的类型是什么? - Mooing Duck