晚上好,我是C ++的新手,但我一直在遇到一些麻烦。
现在,我尝试制作一个列表,经过大量的撤消和更正之后,我发现了无法解决的错误。
#define MAXLIST 100
template <typename T>
class List {
private:
int maxList;
int last = 0;
T* List;
public:
List();
explicit List(int tam);
bool listIsFull();
void destroyList();
List<T>() {
last = -1;
maxList = MAXLIST;
list = new T[maxList];
}
List<T>(int tam) {
last = -1;
maxList = tam;
list = new T[maxList];
}
void destroyList() {
last = -1;
}
bool listIsFull() {
if(last == MAXLIST -1)
return true;
else
return false;
}
}
在我的IDE中,这两种方法destroyList()和listIsFull()都显示类似“不能重载”的错误,并且两个构造函数都显示诸如这样的错误:“不命名类型”
那是什么,我做错了吗?先感谢您。
您的代码在我看来的方式是,尝试对类进行原型设计,然后在其下提供实现,我只是添加了正确的作用域和模板运算符。
#define MAXLIST 100
template <typename T>
class List {
private:
int maxList;
int last = 0;
T* List;
public:
List();
explicit List(int tam);
bool listIsFull();
void destroyList();
};
template<typename T>
List<T>::List<T>() {
last = -1;
maxList = MAXLIST;
list = new T[maxList];
}
template<typename T>
List<T>::List<T>(int tam) {
last = -1;
maxList = tam;
list = new T[maxList];
}
template<typename T>
void List<T>::destroyList() {
last = -1;
}
template<typename T>
bool List<T>::listIsFull() {
if (last == MAXLIST - 1)
return true;
else
return false;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句