以下是跳过列表的模板化类中的内部嵌套类。我在下一行声明了错误:“高度未在此范围内声明”。错误:无效使用非静态数据成员,未在此范围内声明变量
class Node{
public:
Node(int height){
this->height = height;
}
Node(Key_t key, Mapped_t obj, int height){
value = std::make_pair(key, obj);
this->height = height;
}
SkipList<Key_t, Mapped_t>::Node *next[height];
int getHeight(){return height;}
Key_t getKey(){return value.first;}
Mapped_t getObj(){return value.second;}
private:
std::pair<Key_t, Mapped_t> value;
int height;
};
运动的价值和高度声明一切之前,如下所示,改变错误“无效使用非静态数据成员的。
class Node{
private:
std::pair<Key_t, Mapped_t> value;
int height;
public:
Node(int height){
this->height = height;
}
Node(Key_t key, Mapped_t obj, int height){
value = std::make_pair(key, obj);
this->height = height;
}
SkipList<Key_t, Mapped_t>::Node *next[height];
int getHeight(){return height;}
Key_t getKey(){return value.first;}
Mapped_t getObj(){return value.second;}
};
我不知所措作为。怎样做才能解决这个问题这里是整个类:
template <class Key_t, class Mapped_t>
class SkipList{
public:
SkipList(int prob, int max){
probOutOf100 = prob;
maxHeight = max;
head = new SkipList<Key_t, Mapped_t>::Node(maxHeight);
tail = new SkipList<Key_t, Mapped_t>::Node(maxHeight);
for(int i = 0; i < maxHeight; i++){
head->next[i] = tail;
}
}
~SkipList(){
delete head;
delete tail;
}
class Node{
public:
Node(int height){
this->height = height;
}
Node(Key_t key, Mapped_t obj, int height){
value = std::make_pair(key, obj);
this->height = height;
}
SkipList<Key_t, Mapped_t>::Node *next[height];
int getHeight(){return height;}
Key_t getKey(){return value.first;}
Mapped_t getObj(){return value.second;}
private:
std::pair<Key_t, Mapped_t> value;
int height;
};
Node *head;
Node *tail;
int probOutOf100;
int maxHeight;
}