2014-02-28 82 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