-1
テンプレートを使用して定義するバイナリ検索ツリーがあります。これらは、ヘッダーです:例えばエラーC2244テンプレートを使用している間、関数定義を既存の宣言に一致させることができません
template <class T>
class BSNode
{
public:
BSNode(T data);
BSNode(const BSNode& other);
virtual ~BSNode();
virtual BSNode* insert(T value);
BSNode& operator=(const BSNode& other);
bool isLeaf() const;
T getData() const;
BSNode* getLeft() const;
BSNode* getRight() const;
bool search(T val) const;
int getDepth(const BSNode& root) const;
void printNodes() const;
protected:
T _data;
BSNode* _left;
BSNode* _right;
int _count; // if there are duplicated items.
int BSNode::getCurrNodeDistFromInputNode(const BSNode* node) const; // help func to get depth.
};
しかし、いくつかの理由のために私はいつもゲッターの「定義と一致することができない」というエラーを取得したり、「クラステンプレートの使用はarguementリストを必要とする」
、このコードの利回り「定義に一致できません」というエラーです。
template<class T>
BSNode* BSNode<T>::getLeft() const
{
return this->_left;
}
template<class T>
BSNode* BSNode<T>::getRight() const
{
return this->_right;
}
このコード利回り「クラステンプレートを使用すると、引数リストが必要です」:
template<class T>
BSNode* BSNode<T>::insert(T value)
{
// check where should insert the node - right or left
if (value < this->_data)
{
if (_left) // if there is already left son
{
_left = _left->insert(value); // recursive call on the left son
}
else
{
_left = new BSNode(value); // add the node as left son
return *this;
}
}
else if (value > this->_data)
{
if (_right) // if there is already right son
{
_right = _right->insert(value); // recursive call on the right son
}
else
{
_right = new BSNode(value); // add the node as right son
return *this;
}
}
else //value == this->_data
{
this->_count++;
return *this;
}
return *this;
}
私は私の問題は、署名であるが、それでも私は完全なコードを投稿かなり確信しています。誰かがなぜ私はこの問題を抱えているのか、私は何が間違っているのかを理解するのを手助けできますか?
あなたはいくつかの場所で「」を省略しました。クラス定義外のほとんどの場所で必要です。 –
molbdnilo
エラーを言い換えません。それをそのまま生まれ変わらせてください。 – tambre
エラーが発生した行を正確に表示します。 – CiaPan