【发布时间】:2017-10-19 15:02:09
【问题描述】:
我正在尝试使用指向节点的指针的链接列表。 List 是 Node 的容器类。我正在尝试为列表格式化一个查找函数,该函数在链接列表中找到该节点时返回指向该节点的指针。但是,我不断收到错误消息,说没有类型说明符。 (错误显示在下面链接的屏幕截图中,主要查看 Node.h 中的第 10 行和第 17 行)。如何正确格式化以消除错误? https://imgur.com/vicL8FS
NODE.H //Both class declarations contained here
class list //container class
{
public:
list();
~list();
void insert(string f, string l, int a);
node *find(string first, string last); //Pointer to contained class
private:
node *head; //errors here
int length;
};
class node
{
friend list;
public:
node(); // Null constructor
~node(); // Destructor
void put(ostream &out); // Put
bool operator == (const node &); // Equal
private:
string first, last;
node *next;
};
NODE.CPP
#include "Node.h"
node list::*find(string first, string last)
{
return NULL; //logic not written yet
}
//MAIN
p = a.find(first, last); //p is a pointer to node, a is a list.
【问题讨论】:
-
试试
node *list::find(string first, string last)。 -
那行不通。它只是增加了另一个错误
-
可能,但
node *list::find(string first, string last)无效。因为返回类型是node *,函数名是list::find。你不能混合它们。 -
请将错误连同问题一起粘贴到此处。不要链接屏幕截图。这将有助于在一个视图中更好地理解您的问题。
-
我刚刚将您的新声明与下面列出的其他答案结合起来,错误已清除!
标签: c++ function class pointers containers