我被困在这里。我收到错误消息,说我仅对treeHeight有未定义的引用。在构造函数中以及在使用treeHeight的成员函数定义中。模板化类中可以没有静态变量吗?
template <class T> // base element type
class Position // a node position
{
public:
Position(const int& HEIGHT) { treeHeight = HEIGHT; }
PositionList<T> children() const; // (0) left, (1) duplicate, (2) right
bool isRoot() const { return parent() == nullptr; }
bool isExternal() const { return leftNode == nullptr
&& rightNode == nullptr; }
void incDepth();
/* Getters */
T operator*() const { return data; } // get element
Position<T> * parent() const { return parentNode; }
// Position<T> * duplicate() const { return duplicNode; }
// Position<T> * left() const { return rightNode; }
// Position<T> * right() const { return leftNode; }
friend void BTClass<T>::insert(Position<T> *, const T&);
private:
Position<T> * parentNode {nullptr};
Position<T> * leftNode {nullptr}; // Less than parent
Position<T> * duplicNode {nullptr}; // Equal to parent
Position<T> * rightNode {nullptr}; // Greater than parent
T data {T()};
int depth {0}; // Depth of current node within tree. (cannot exceed height)
static int treeHeight;
};