2012-11-04 12 views
2

我想聲明這樣一個列表的列表清單:「從這裏需要」的錯誤聲明列表

List_vector<List_vector<int> > multilist; 

但是Eclipse強調了上述聲明,並給出了這個錯誤:

required from here

部分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 
+0

給我們Eclipse提供的完整的錯誤,這不足以知道什麼是錯的。你有沒有包含List_vector頭文件? – alestanis

+1

這是完整的錯誤,是的,包含頭文件。 – Hoconosc

+0

Eclipse只打印一行?請參閱控制檯選項卡,您將找到編輯問題的錯誤 – alestanis

回答

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的代碼,但它似乎是做錯了什麼:該功能的每一個路徑應返回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] 
+0

Linear_list類沒有構造函數/析構函數。雖然第二次戰鬥是可以的(一個if內的回報)。 – Hoconosc

+0

返回'if'內部不是問題。但是你不能只從'if'內部返回,因爲如果採用'else'路徑會發生什麼? – Useless

+0

使用不同的編譯器(MINGW32附帶Dev C++解決了這個問題) – Hoconosc

相關問題