2

我正在尝试以这种方式声明列表列表:

List_vector<List_vector<int> > multilist;

但是 Eclipse 强调了上述声明并给出了这个错误:

从这里需要

部分 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 
4

1 回答 1

1
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,您应该考虑将析构函数设为虚拟,就像它说的那样。这只是一个警告,只有你知道它是否真的需要(没有足够的代码粘贴来判断)。

..\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,但它似乎做错了什么:函数的每条路径都应该返回 a 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]
于 2012-11-04T11:38:49.513 回答