“从这里需要”错误声明列表列表 [英] "required from here" error declaring a List of Lists
问题描述
我想以这种方式声明一个列表的列表:
I'm trying to declare a list of lists in this way:
List_vector<List_vector<int> > multilist;
但是Eclipse强调了上述声明并给出了这个错误:
But Eclipse underlines the above declaration and gives this error:
required from here
部分List_vector实施:
Partial List_vector implementation:
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
,你应该考虑使析构函数虚拟,就像它说的。这只是一个警告,但只有你知道它是否真的需要(没有足够的代码粘贴来判断)。
If you're going to derive from Linear_List
, you should consider making the destructor virtual, like it says. This is only a warning though, and only you know whether it is really required (there isn't enough code pasted to judge).
..\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
(除非它抛出异常),但是你让控制到达
You haven't pasted the code for List_vector::read
, but it seems to be doing something wrong: every path out of the function should return a List_vector::value_type
(unless it throws an exception), but you're letting control reach the end without doing either.
..\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]
这篇关于“从这里需要”错误声明列表列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!