嘿家伙,所以我得到这个错误,当我试图为我的链表类创建此函数。我遇到的问题是我的搜索功能。我还没有开始创建函数,但是我收到的错误是在搜索函数的声明中。在NODEPTR线下38它说,这是不确定的,并在搜索它说错误:与声明“的LinkedList :: NODEPTR不兼容(在线17声明)的代码如下任何帮助表示赞赏链接列表...声明与原型不兼容
// LinkedListProject.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <list>
using namespace std;
class LinkedList {
public:
struct Node {
int data;
Node* link;
};
typedef Node* NodePtr;
//NodePtr head = new Node;
void head_insert(NodePtr& head, int the_number);
NodePtr search(NodePtr head, int target);
private:
};
int main()
{
LinkedList obj;
//obj.head->data = 3;
//obj.head->link = NULL;
return 0;
}
void LinkedList::head_insert(NodePtr& head, int the_number) {
NodePtr temp_ptr = new Node;
temp_ptr->data = the_number;
temp_ptr->link = head;
head = temp_ptr;
}
NodePtr LinkedList::search(NodePtr head, int target)
{
return NodePtr();
}
在实现中更改返回类型“LinkedList :: NodePtr”而不是“NodePtr”。 –
或者,'auto LinkedList :: search(NodePtr head,int target) - > NodePtr' – aschepler