c++ - 与参数包声明混淆,C++

标签 c++ c++11 templates parameters

谁能解释一下下面的声明是什么意思?

template<typename... T> void f2(std::vector<T*>...);

这是否意味着 f2 接受具有不同指针类型的 std::vectors 数量?

最佳答案

Does this mean that f2 accepts number of std::vectors with different pointer types?

是的!

template<typename... T> void f2(std::vector<T*>...) {}

int main()
{
    std::vector<int*> vi;
    std::vector<double*> vd;

    f2( vi, vd );
}

提示: 如果运行 gcc,您可以使用:

template<typename... T> void f2(std::vector<T*>...) 
{   
    std::cout << __PRETTY_FUNCTION__ << std::endl;
}  

将输出:

void f2(std::vector<T*>...) [with T = {int, double}]

关于c++ - 与参数包声明混淆,C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49552006/

相关文章:

c++ - Cocos2dx InApp Purchase for ios

c++ - 使用第二列对二维数组进行排序 C++

c++ - 前向声明是行不通的

c++ - 这里的 const 修饰符不是不必要的吗?

c++ - 编写值包装器类的最佳方法

c++ - 编译器优化 "constant propagation"是什么意思?

c++ - 命名执行多个操作的方法

c++ - 模板元编程示例没有意义

c++ - 模板类,函数特化

css - 模板 : negative margins on float 有问题