c++ template NULL undeclared identifier -
i having problems in c++ templates , null. trying make bst in c++ using templates. have class element, treeelement , binarysearchtree.
a binarysearchtree has treeelements nodes. each treeelement has linkedlist of elements. each element has long indentify , check whether it's <, > or ==.
now error: null undeclared identifier. don't know how it's possible. here's code of treeelement error:
template <class t> class treeelement { private: treeelement* lefttree; treeelement* righttree; treeelement* parent; element<t>* value; public: //here error!! treeelement(element<t>* element){value = element; lefttree = null; righttree = null; parent = null;}; ~treeelement() { element<t>* nextelement; if (value != null) { while (value->getnextelement() != null) { nextelement = value; value = nextelement->getnextelement(); delete nextelement; } delete value; } }; treeelement* getlefttree(){return this->lefttree;}; treeelement* getrighttree(){return this->righttree;}; treeelement* getparent(){return this->parent;}; element<t>* getvalue(){return this->value;}; void setlefttree(treeelement* lefttree){this->lefttree = lefttree;}; void setrighttree(treeelement* righttree){this->righttree = righttree;}; void setparent(treeelement* parent){this->parent = parent;}; void setvalue(element<t>* value){this->value = value;}; };
three options:
- include header
<cstddef>
definesnull
- use null pointer constant,
0
or (since c++11)nullptr
rather dodgy macro - don't compare null, use pointer in boolean context same effect (although applies 1 of uses of
null
here)
Comments
Post a Comment