バイナリ検索ツリークラスを実装しようとしていますが、コンパイラがエラーを投げています。コンパイラは、呼び出しに一致する関数がないことを示しています(プロトタイプに1つあります)
template <class Item, class Key>
class bstNode
{
public:
bstNode();
bstNode(const Item& init_data, const Key& init_key, bstNode<Item, Key> *init_left, bstNode<Item, Key> *init_right);
~bstNode();
bstNode<Item, Key>* tree_copy(const bstNode<Item, Key>*& root);
private:
Item data;
Key key;
bstNode* left;
bstNode* right;
};
template <class Item, class Key>
//line 83 in the original code is below
bstNode<Item, Key>* bstNode<Item, Key>::tree_copy(const bstNode<Item, Key>*& root)
{
bstNode<Item, Key>* l_ptr;
bstNode<Item, Key>* r_ptr;
if (root == NULL) return NULL;
l_ptr = tree_copy(root -> left());
r_ptr = tree_copy(root -> right());
return new bstNode<Item, Key> (root -> data(), l_ptr, r_ptr);
}
.hファイルが空の主な機能と罰金コンパイルが、私はbstNode.cxxで次のコードビットでそれをしようとすると、それがエラーを与えて、クラッシュ:bstNode.hファイルはこちらです。
#include <cstddef>
#include <algorithm>
#include <math.h>
#include <iostream>
#include "bstNode.h"
using namespace std;
int main()
{
bstNode<int, size_t>* root_ptr = NULL;
bstNode<int, size_t>* copy_root_ptr = root_ptr -> tree_copy(root_ptr);
return 0;
}
し、エラーがある:コードがある
bstNode.cxx: In function ‘int main()’:
bstNode.cxx:14: error: no matching function for call to ‘bstNode<int, long unsigned int>::tree_copy(bstNode<int, long unsigned int>*&)’
bstNode.h:83: note: candidates are: bstNode<Item, Key>* bstNode<Item, Key>::tree_copy(const bstNode<Item, Key>*&) [with Item = int, Key = long unsigned int]
プロトタイプは、関数の実装と全く同じである、サンセリフbstNode ::ので、私は何が起こっているのかわかりません。私はg ++コンパイラを使用しています。何か案は?ありがとう、ありがとう。
EDIT:問題を強調表示するためにコードを縮小しました。
問題を切り分けることができれば、(あなたも)助けになります。エラーを示している最小の完全なプログラムにプログラムを縮小してください。 http://sscce.org/。 –
[非ポインタへのポインタへのポインタからポインタへのポインタへの変換はなぜ合法ではないのですか?](http://stackoverflow.com/questions/2220916/why-isnt-それを法律に変換するポインタからポインタへの非ポインタへの変換)ポインターへの参照としても有効です。 –