C++中的可比较项数组
Array of Comparables in C++
我的代码中出现以下错误。我对C++非常生疏,不确定自己做错了什么。
错误消息:
Error: Field has incompatible type 'int []'
代码:
template<typename Comparable> class OrderedCollection
{
private:
Comparable data[]; //ERROR CAUSED BY THIS LINE
int _size;
int _current;
const int MAX_SIZE = 100;
对此可能的修复方法是使用第二个接受size_t的模板参数。
template<typename Comparable, size_t MAX_SIZE = 100> class OrderedCollection
{
private:
Comparable data[MAX_SIZE]; //Error should be gone
int _size;
int _current;
您需要指定const
数组大小,数组大小必须在编译时已知。
像这样的东西应该修复:
Comparable data[MAX_SIZE];
相关文章:
- 比较字符数组
- 在这里,当我们比较 if(vc[i]==vc1[i]) 时,它是向量数组. 实际上比较的值是多少,
- 如何将字符串字符与结构数组进行比较?
- 在C++中返回基元类型数组(Java比较)
- 将子字符串与字符串数组进行比较的 IF 条件会在C++中产生错误
- 字符指针对象和相应的字符数组元素比较
- 开发C++数组元素比较
- 如何将一个值与整个数组进行比较
- 我怎样才能洗牌给定大小的数组并将其与C++中另一个相同大小的数组进行比较
- 在将数组与字符数组进行比较后需要帮助输出一次结果
- 如何将单个字符串与字符串数组进行比较
- 如何将字符串变量与从文件创建的字符串数组进行比较
- 将字符串与 2D 数组进行比较
- 通过C和C++中的二维数组的比较
- 如何将 litere 与带有 "(" 个字符数组进行比较
- 将二维int数组与字符串数组C++进行比较
- C++中的可比较项数组
- 如何将矢量与数组进行比较
- 简单的c++数组元素比较
- 搜索数组并比较它们