在.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)
使用,而不是一个向量的常量矢量&请声明你的构造。矢量复制不是最佳选择。 –
ebasconp