C++ 中的列表,重载方法?
Lists in C++, Overloading methods?
晚上好伙计们,我是 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() 两种方法都显示如下错误:'Cannot be overloaded'
并且两个构造函数都显示如下错误:'Does not name a type'
那是什么,我做错了吗?
提前谢谢你。
你的代码在我看来是这样的,你试图为你的 class 制作原型,然后在它下面提供实现,我只是添加了正确的范围和模板运算符。
#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;
}
晚上好伙计们,我是 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() 两种方法都显示如下错误:'Cannot be overloaded' 并且两个构造函数都显示如下错误:'Does not name a type'
那是什么,我做错了吗? 提前谢谢你。
你的代码在我看来是这样的,你试图为你的 class 制作原型,然后在它下面提供实现,我只是添加了正确的范围和模板运算符。
#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;
}