[英]Unknown type error in C++ when I return Node *
When I compile, I got " error: unknown type name 'Node'" 编译时,出现“错误:未知类型名称'Node'”
It comes from *Node * findKthElementToLast(int k)* function since it returns Node * type 它来自* Node * findKthElementToLast(int k)*函数,因为它返回Node *类型
I am not able to solve it. 我无法解决。 Any help would be nice!
你能帮忙的话,我会很高兴!
LinkedList.h LinkedList.h
#ifndef LINKEDLIST_H
#define LINKEDLIST_H
#include <cstdlib>
#include <iostream>
using namespace std;
template<class DataType>
class LinkedList{
struct Node {
DataType dataIn;
Node * next;
};
public:
LinkedList();
~LinkedList();
bool insertHead(DataType dataNew);
bool insertTail(DataType dataNew);
bool removeHead();
bool removeTail();
bool remove(DataType dataOut);
bool removeDuplicates();
bool removeDuplicatesUsingHash();
bool search(DataType dataSearch);
Node * findKthElementToLast(int k);
void printLinkedList();
private:
Node * head;
};
#endif
findKthElementToLast function from LinkedList.cpp 来自LinkedList.cpp的findKthElementToLast函数
template<class DataType>
Node * LinkedList<DataType>::findKthElementToLast(int k){
if(head == NULL){
return head;
}
Node * iter1 = head;
Node * iter2 = head;
int counter = 1;
while(counter < k){
counter++;
iter2 = iter2->next;
}
while(iter2->next != NULL){
iter1 = iter1->next;
iter2 = iter2->next;
}
return iter1;
}
Should be 应该
template<class DataType>
LinkedList<DataType>::Node *LinkedList<DataType>::findKthElementToLast(int k) {
Node is declared inside the LinkedList class, so any references from outside that class must be qualified. Node在LinkedList类内部声明,因此该类外部的任何引用都必须是合格的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.