简体   繁体   中英

Error - ListNode does not name a type

In the .h file,

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

In the .cpp file

 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 26 in .cpp, error: ListNode does not name a type. I'm quite sure I did everything right. Annoying. EDIT: Following a reply, I updated my code.

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)

ListNode被内部定义的DataStructure ,所以你不得不说, DataStructure::ListNode的返回类型findnode功能。

您应该编写一个函数来填充您的struct调用,然后定义findNone

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM