2013-02-10 78 views
-1

我得到一個編譯器錯誤,說傳遞不同類型的載體爲模板功能

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); 
    ... 
} 
+4

'vector &'意味着你想要一個指針向量,並且你給它一個非指針向量。 – 2013-02-10 01:42:55

+0

你爲什麼要做'矢量'而不只是'矢量'? – 0x499602D2 2013-02-10 02:07:40

回答

0

int無法比擬T*

要麼使vector a vector<int*>或使模板採取vector<T>