C++ 错误-ListNode未命名类型

C++ 错误-ListNode未命名类型,c++,struct,C++,Struct,在.h文件中 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 publ

在.h文件中

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

ListNode
是在
DataStructure
中定义的,因此对于
findnode
函数的返回类型,您必须说
DataStructure::ListNode

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

不工作。。。编辑问题以尝试您的想法您似乎没有向我们展示提交给编译器的真实代码。问题中的第21行显示返回指针的
findnode
,但编译器消息表明编译器将
ListNode
(非指针)视为返回类型。一般来说,更改为带更正的发布代码是不好的,因为此时问题和发布的答案没有意义。而是把这些变化作为问题的补充。谢谢你的提示,史蒂夫。我再次核对了这个问题。正如我编译的那样。我还仔细检查了我的目录和文件名。好吧,仍然是第21行与编译器错误消息不匹配,这意味着您发布的代码不是您提交给编译器的代码。编译器消息中的行号也不匹配。请使用常量向量而不是向量声明构造函数。向量复制不是最优的。
 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 }
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)