template<class Elem>
class BinNode//Binary tree node abstract class.
{
public:
virtual Elem& val() = 0;//return the node's element;
virtual void setVal(const Elem&) = 0;//set the node's element;
virtual BinNode* left() const = 0;//return the node's left child;
virtual BinNode* right() const = 0;//return the node's right child;
virtual void setLeft(BinNode*) = 0;//set the node's left child's element;
virtual void setRight(BinNode*) = 0;//set the node's right child's element;
};
template<class Elem>
class BinNodePtr:public BinNode<Elem>
{
public:
Elem ele;//the content of the node
BinNodePtr<Elem>* lc;//the node's left child
BinNodePtr<Elem>* rc;//the node's right child
public:
static int now_on;//the node's identifier
BinNodePtr(){lc = rc = NULL;ele = 0;};//the constructor
~BinNodePtr(){};//the destructor
void setVal(const Elem& e){this->ele = e;};
Elem& val(){return ele;}//return the element of the node
inline BinNode<Elem>* left()const//return the node's left child
{
return lc;
}
inline BinNode<Elem>* right()const//return the node's right child
{
return rc;
}
void setLeft(const Elem& e){lc->ele = e;}//to set the content of the node's leftchild
void setRight(const Elem& e){rc->ele = e;}//to set the content of the node's rightchild
};
int main()
{
BinNodePtr<int> root;//initiate a variable//the error is here.
BinNodePtr<int> subroot = &root;//initiate a pointer to the variable
}
빌드 할 때 컴파일러에서 "추상 클래스를 인스턴스화 할 수 없습니다"라고 말했습니다. 그리고 오류는 BinNodePtr 루트에 있습니다. 나는 추상 클래스를 인스턴스화하지 않고 추상 클래스에서 파생 된 클래스입니다. 어떻게 해결할 수 있습니까?추상 클래스에서 파생 된 클래스를 인스턴스화하는 방법
당신은 정의'setLeft'와'BinNodePtr''에 다른 매개 변수를 setRight'. – Brian