无效地使用不完整的类型模板构造函数声明
invalid use of incomplete type template constructor declaraion
下面是我的模板类。为什么会出现错误?
template <typename Key_T, typename Mapped_T, size_t MaxLevel = 5>
class SkipList
{
typedef std::pair<Key_T, Mapped_T> ValueType;
public:
SkipList();
SkipList(const SkipList &);
SkipList &operator=(const SkipList &);
size_t size() const;
Iterator<Key_T,Mapped_T> begin();
Iterator<Key_T,Mapped_T> end();
//ConstIterator begin() const;
//ConstIterator end() const;
virtual void clear();
std::pair<Iterator<Key_T,Mapped_T>, bool> insert(const ValueType &);
template <typename IT_T>
void insert(IT_T range_beg, IT_T range_end);
virtual void erase(Iterator<Key_T,Mapped_T> pos);
virtual void erase(Iterator<Key_T,Mapped_T> range_beg, Iterator<Key_T,Mapped_T> range_end);
private:
Iterator<Key_T,Mapped_T>* head;
Iterator<Key_T,Mapped_T>* tail;
float probability;
size_t maxHeight;
size_t curHeight;
RandomHeight* randGen;
};
template <typename Key_T1,typename Mapped_T1,typename Key_T2,typename Mapped_T2>
bool operator==(const SkipList<Key_T1,Mapped_T1> &a, const SkipList<Key_T2,Mapped_T2> &b);
template <typename Key_T1,typename Mapped_T1,typename Key_T2,typename Mapped_T2>
bool operator!=(const SkipList<Key_T1,Mapped_T1> &a, const SkipList<Key_T2,Mapped_T2> &b);
template <typename Key_T1,typename Mapped_T1,typename Key_T2,typename Mapped_T2>
bool operator<(const SkipList<Key_T1,Mapped_T1> &a, const SkipList<Key_T2,Mapped_T2> &b);
template <typename Key_T, typename Mapped_T>
SkipList<Key_T,Mapped_T>::SkipList() : curHeight (1), maxHeight(MaxLevel) , probability (1.0/MaxLevel)
{
randGen = new RandomHeight(MaxLevel,probability);
// Create head and tail and attach them
head = new Iterator<Key_T,Mapped_T> (maxHeight);
tail = new Iterator<Key_T,Mapped_T> (maxHeight);
head->fwdNodes = tail;
}
错误:SkipList.cpp:134:36: error: invalid use of incomplete type ‘class SkipList<Key_T, Mapped_T>’
SkipList.cpp:93:7: error: declaration of ‘class SkipList<Key_T, Mapped_T>’
你的类SkipList
有三个模板参数。
template <typename Key_T, typename Mapped_T, size_t MaxLevel = 5>
class SkipList
你必须在这里说明。
// I've added "size_t MaxLevel"
template <typename Key_T, typename Mapped_T, size_t MaxLevel>
SkipList<Key_T,Mapped_T,MaxLevel>::SkipList() : curHeight (1), maxHeight(MaxLevel) , probability (1.0/MaxLevel)
另外,如果(仅当)需要在其他编译单元中访问这个模板化的构造函数,应该在头文件中定义它。
你少了一个参数,你只有两个,但你需要三个,这是可行的:
template <typename Key_T, typename Mapped_T, size_t MaxLevel>
SkipList<Key_T,Mapped_T,MaxLevel>::SkipList() : curHeight (1), maxHeight(MaxLevel) , probability (1.0/MaxLevel)
相关文章:
- 我不明白为什么我声明一个空的内部结构并将其传递给构造函数
- 将派生类的构造函数声明为父类的友元
- 用初始化列表和超类构造函数声明子类构造函数的正确方式
- 如何使用构造函数声明指向用户定义对象的指针?
- 如何从构造函数声明新的私有变量?
- 根据二手构造函数声明成员
- 如何用类别的consumetrized构造函数声明使用类的比较对象设置的STL设置
- C++.奇怪的构造函数声明
- 使用ctags查找用c++中的构造函数声明的变量
- 将构造函数声明为private会显示错误.是否至少有一个公共构造函数是必需的
- 如何在C++中使用带参数的构造函数声明具有来自另一个类的类数据的对象
- 在构造函数声明中编写模板类型的参数列表是否有效?
- 在另一个类中使用自定义构造函数声明一个类
- 谷歌测试-构造函数声明错误
- 使用构造函数声明作为虚函数
- 无效地使用不完整的类型模板构造函数声明
- 将构造函数声明为显式时出现编译错误
- 它在构造函数声明中意味着什么
- 类构造函数声明了两次
- 有一种方法可以使用默认的复制构造函数声明复制构造函数非公共和?