2

I'm trying to declare a list of lists in this way:

List_vector<List_vector<int> > multilist;

But Eclipse underlines the above declaration and gives this error:

required from here

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
};

Compiler output:

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 
Oktalist
  • 14,336
  • 3
  • 43
  • 63
Hoconosc
  • 416
  • 9
  • 24
  • Give us the full error given by Eclipse, that's not enough to know what's wrong. Did you include the List_vector header file? – alestanis Nov 04 '12 at 11:28
  • 1
    That's the full error, and yes, the header is included. – Hoconosc Nov 04 '12 at 11:29
  • Eclipse only prints one line? See the Console tab, you will find a full trace of the error – alestanis Nov 04 '12 at 11:29
  • Could you please point out line 78 and 136 of the file `list_vector.h`? Although one of the warnings may be that you use inheritance but don't have virtual desctructors. – Some programmer dude Nov 04 '12 at 11:36
  • 2
    There are only warnings, no errors, right? And they are pretty clear: You use class inheritance, but your destructor isn't virtual, and you have a function that is supposed to a return a value, but doesn't. – jogojapan Nov 04 '12 at 11:37
  • 2
    "Required from here" is not an error. It tells you additional information about why that instantiation was required. The real error (or warning) is in the lines that follow. Please update your question to reflect the actual error. – Mat Nov 04 '12 at 11:37

1 Answers1

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]

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]

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]
Useless
  • 64,155
  • 6
  • 88
  • 132
  • The Linear_list class has not a costructor/destructor. While the second waring is ok (a return inside an if). – Hoconosc Nov 04 '12 at 11:54
  • Returning inside an `if` is not a problem. But you can't _only_ return from inside an `if`, because what happens if the `else` path is taken? – Useless Nov 04 '12 at 12:07
  • using a different compiler (MINGW32 which comes with Dev C++ solved the problem) – Hoconosc Nov 11 '12 at 12:17