将不同类型的向量传递给模板函数

时间:2013-02-10 01:40:44

标签: c++ templates vector

我收到的编译错误是

could not deduce template argument for 'std::vector<T*>&' from 'std::vector<_Ty>'

template <typename T> void foo(vector<T*>& a, int left, int right)
{
     ...
}

main()
{
     ...
     //declare and instantiate 3 vectors
     vector<int> intVector;

     foo(intVector, 0, 100);
     foo(doubleVector, 0, 100);
     foo(charVector, 0, 100);
     ...
}

1 个答案:

答案 0 :(得分:0)

int无法匹配T*

vector设为vector<int*>或将模板设为vector<T>