我想檢查兩個向量是否有任何共同的元素。這個語法有什麼問題?C++將向量傳遞給函數模板
// Check whether the current list and the input l2 share any nodes or not
bool shared(const VectorList<NODETYPE> &l2);
template< typename NODETYPE > //SHARED
bool VectorList< NODETYPE>::shared(const VectorList<NODETYPE> &l2)
{
for(int i = 0; i < (int)vList.size(); i++)
{
for (int j = i; j < (int)l2.size() ; j++)
{
if (vList[i] == l2[j])
{
return(1);
}
}
}
return(0);
}
你可能想發佈爲什麼你認爲你的代碼有問題。如果這是一個編譯器錯誤,編譯器的名稱及其版本也可能有所幫助。 – sbi
總是發佈編譯器錯誤。他們已經完成檢查語法,以便人們不會自己做。 – Beginner
你知道'std :: vector'不是懶惰,你應該使用它以及爲標準模板容器設計的STL算法。 – AJG85