声明列表列表时"required from here"错误
"required from here" error declaring a List of Lists
我正在尝试以这种方式声明列表:
List_vector<List_vector<int> > multilist;
但日食强调了上述声明并给出了此错误:
从这里需要
部分list_vector实现:
template<class T>
class List_vector: public Linear_list<T, int> {
public:
typedef typename Linear_list<T, int>::value_type value_type;
typedef typename Linear_list<T, int>::position position;
List_vector();
List_vector(int);
List_vector(const List_vector<T>&);
~List_vector();
private:
void change_dimension_(T*&, int, int);
value_type* elements_;
int length_; // the length of the list
int array_dimension_; // array's dimension
};
编译器输出:
g++ -O3 -Wall -c -fmessage-length=0 -o multilista.o "..\multilista.cpp"
In file included from ..multilista.cpp:1:0:
..list_vector.h: In instantiation of 'List_vector<T>::~List_vector() [with T = List_vector<int>]':
..multilista.cpp:16:32: required from here
..list_vector.h:78:5: warning: deleting object of polymorphic class type List_vector<int>' which has non-virtual destructor might cause undefined behaviour [-Wdelete-non-virtual-dtor]
..list_vector.h: In member function 'List_vector<T>::value_type List_vector<T>::read(List_vector<T>::position) const [with T = int; List_vector<T>::value_type = int; List_vector<T>::position = int]':
..list_vector.h:136:1: warning: control reaches end of non-void function [-Wreturn-type]
..list_vector.h: In member function 'List_vector<T>::value_type List_vector<T>::read(List_vector<T>::position) const [with T = List_vector<int>; List_vector<T>::value_type = List_vector<int>; List_vector<T>::position = int]':
..list_vector.h:136:1: warning: control reaches end of non-void function [-Wreturn-type]
g++ -O3 -Wall -c -fmessage-length=0 -o tester.o "..\tester.cpp"
g++ -o Lista.exe tester.o multilista.o
In file included from ..multilista.cpp:1:0:
..list_vector.h: In instantiation of 'List_vector<T>::~List_vector() [with T = List_vector<int>]':
..multilista.cpp:16:32: required from here
..list_vector.h:78:5: warning: deleting object of polymorphic class type 'List_vector<int>' which has non-virtual destructor might cause undefined behaviour [-Wdelete-non-virtual-dtor]
如果您要衍生出Linear_List
,则应考虑使destructor虚拟化,就像它所说的那样。不过,这只是一个警告,只有您知道它是否真的需要(没有足够的代码来判断)。
..list_vector.h: In member function 'List_vector<T>::value_type List_vector<T>::read(List_vector<T>::position) const [with T = int; List_vector<T>::value_type = int; List_vector<T>::position = int]':
..list_vector.h:136:1: warning: control reaches end of non-void function [-Wreturn-type]
您尚未粘贴List_vector::read
的代码,但是它似乎在做错事:函数中的每个路径都应返回List_vector::value_type
(除非抛出异常)这两个。
..list_vector.h: In member function 'List_vector<T>::value_type List_vector<T>::read(List_vector<T>::position) const [with T = List_vector<int>; List_vector<T>::value_type = List_vector<int>; List_vector<T>::position = int]':
..list_vector.h:136:1: warning: control reaches end of non-void function [-Wreturn-type]
相关文章:
- Pybind11:将元组列表从Python传递到C++
- 从链接列表c++中删除一个项目
- 如何(从固定列表中)选择一个数字序列,该序列将与目标数字相加
- C++如何通过用户输入删除列表元素
- 读取文件的最后一行并输入到链接列表时出错
- 复制列表初始化的隐式转换的等级是多少
- LNK2038、MSVS2017 MAGMA的原因列表
- 不能在初始值设定项列表中将非常量表达式从类型 'int' 缩小到'unsigned long long'
- 没有为自己的结构调用列表推回方法
- 使用简单类型列表实现的指数编译时间.为什么
- 一对向量构造函数:初始值设定项列表与显式构造
- 标准是否使用多余的大括号(例如 T{{{10}}})定义列表初始化?
- 通过for循环使用用户输入填充列表
- C++:如何使函数只返回作为列表一部分的字符串
- 概念中的cv限定符需要表达式参数列表
- 下面是我为检测链接列表中的循环而制作的代码
- 建议在运行时将带有类实例的列表从c++导入qml
- 如何维护资源管理器项目视图中当前可见的项目列表
- 在卡萨布兰卡形成编码参数的列表
- 声明列表列表时"required from here"错误