クラス BSTNode をテンプレート化しました。
BSTNode.h
#ifndef _NODE_BST_H_
#define _NODE_BST_H_
template <class K, class T>
struct BSTNode
{
typedef K keyType;
typedef T elementType;
keyType _key;
elementType _element;
BSTNode<keyType,elementType>* _leftChild;
BSTNode<keyType,elementType>* _rightChild;
// constructors
BSTNode();
BSTNode<K,T>::BSTNode (keyType, elementType, unsigned int, BSTNode<K,T>*, BSTNode<K,T>*);
/*
some methods
*/
BSTNode<K,T>& operator=(const BSTNode<K,T>& nodoBST2);
};
template <class K, class T>
BSTNode<K,T>::BSTNode ()
{
_leftChild=NULL;
_rightChild=NULL;
}
template <class K, class T>
BSTNode<K,T>::BSTNode (keyType chiave, elementType elemento, unsigned int altezza, BSTNode* figlioSinistro=NULL, BSTNode* figlioDestro=NULL)
{
//constuctor code
}
template <class K, class T>
BSTNode<K,T>& BSTNode<K,T>::operator=(const BSTNode<K,T>& nodoBST2)
{
//operator= code
return *this;
}
#endif
main.c
#include <cstdlib>
#include <iostream>
#include "BSTnode.h"
using namespace std;
int main(int argc, char *argv[])
{
BSTNode<string,string>* node1,node2;
node1=NULL;
node2=node1;
system("PAUSE");
return EXIT_SUCCESS;
}
エラーが発生します
no match for 'operator=' in 'node2 = node1'
candidates are: BSTNode<K, T>& BSTNode<K, T>::operator=(const BSTNode<K, T>&) [with K = std::string, T = std::string]
必要な署名に一致する BSTNode クラスに operator= がありますが。
さらに、node1、node2 はクラス BSTNode へのポインターであるため、私の経験から、実際には operator= さえ必要ないことがわかっています。
何が問題なのですか?誰かが私を見て助けてくれますか?
お時間をいただきありがとうございます。