2014-02-28 83 views
-1

在.h文件,錯誤 - ListNode沒有指定類型

7 using namespace std; 
    8 
    9 class DataStructure { 
10  private: 
11   struct ListNode { 
12    int item; 
13    ListNode *next; 
14   }; 
15   int size; 
16   ListNode *head; 
17 
18  public: 
19   DataStructure(int N, vector<int> elements); 
20 
21   ListNode* findnode(int index); 
22   void move(int index, int siz); 
23 
24 }; 

在.cpp文件

26 DataStructure::ListNode* DataStructure::findnode(int index) { 
27  ListNode *start; 
28  start=head; 
29 
30  for (int i=1; i<index; i++) 
31   start=start->next; 
32 
33  return start; 
34 } 

@line中的.cpp 26,錯誤:ListNode沒有指定類型。 我很確定我做的都對。煩人。 編輯:在回覆後,我更新了我的代碼。

DataStructure.cpp:26:26: error: prototype for 'DataStructure::ListNode* DataStructure::findnode(int)' does not match any in class 'DataStructure' 
DataStructure.h:17:18: error: candidate is: DataStructure::ListNode DataStructure::findnode(int) 
+0

使用,而不是一個向量的常量矢量&請聲明你的構造。矢量複製不是最佳選擇。 – ebasconp

回答

2

ListNode在裏面DataStructure定義,所以你不得不說DataStructure::ListNodefindnode函數的返回類型。

+0

都能跟得上沒有工作...編輯問題,嘗試你的想法。在你的問題中,第21行顯示'findnode'返回一個指針,但編譯器消息指出編譯器將'ListNode'(不是指針)看作返回類型。 –

+0

你似乎沒有表現出我們真正的代碼提交給編譯器 –

+0

Sry,沒有更新.h。讓我現在複製它。 –

0

你應該寫一個函數來填補你的電話struct它,然後定義findNone