2012-12-30 123 views

回答

13

可以初始化std::vector<T>与列表初始化。但是,您不能在参数列表中使用推导出模板参数T使用std::vector<T>,并且传递的函数不是std::vector<T>。例如,它的工作原理如下:

#include <vector> 

template <typename T> 
struct A { 
    void f(const std::vector<T> &) {} 
}; 

int main() { 

    A<int> a; 

    a.f({ 1, 2, 3 }); 

}