ここに記載されているエラーが発生します: C ++テンプレートエラー:呼び出しstd :: vector <int、std ::allocator<int>>に一致する関数がありません
ここにエラーがあります(再び):
main.cpp: In function ‘int main()’:
main.cpp:21:21: error: no matching function for call to ‘Test<int>::foo(std::vector<int, std::allocator<int> >)’
main.cpp:21:21: note: candidate is:
main.cpp:14:6: note: void Test<T>::foo(std::vector<T>&) [with T = int]
main.cpp:14:6: note: no known conversion for argument 1 from ‘std::vector<int, std::allocator<int> >’ to ‘std::vector<int, std::allocator<int> >&’
問題は、私がより複雑な状況にあり、それを解決する方法がわからないことです(あまり多くのコードを壊さずに)。汎用のバイナリ検索ツリークラスがあります。タイプT(generic)の要素のベクトルに、二分探索木ノードからのすべての値を入力したいので、ベクトルをconstにすることはできません。ツリーをトラバースする関数は再帰的です。
ので、私は持っています:
/*main*/
BST<int> t;
t.add(21);
t.add(12);
//.... etc.
vector<int> elements;
t.inorder(elements);
/* ------------ */
と:
/*BST.h*/
template<typename T>
class BST{
//....
Node<T>* root;
//....
void inorder_rec(Node<T>* root, vector<T>& result);
void inorder(vector<T>& result);
//....
};
template<typename T>
void BST<T>::inorder_rec(Node<T>* root, vector<T>& result){
// recursive call for the child nodes
}
void BST<T>::inorder(vector<T>& result){
inorder_rec(this->root, result);
}
/* ------------ */