首先,我想说对不起,可以肯定的是,这个问题将是非常基本的,
但这是我第一次尝试创建链接列表。
问题是当我尝试分配内存并在“ nodeHead”内放入一个新的节点地址时,出现错误消息:
错误C2440:“ =”:无法从“ MatchmakingAgency :: Node *”转换为“ Node *”
IntelliSense:无法将类型“ MatchmakingAgency :: Node *”的值分配给类型“ Node *”的实体
这些是文件:
MatchmakingAgency.h-数据库类
class Node;
#include "Client.h"
#ifndef _MatchmakingAgency_H_
#define _MatchmakingAgency_H_
class MatchmakingAgency
{
private:
Node* nodeHead;
Node* nodeTail;
//Node class
class Node
{
private:
Client* client;
Node* next;
public:
Node();
Node(Client*);
Node(Client*,Node*);
};
//end of Node class
public:
MatchmakingAgency();
MatchmakingAgency(Client*);
~MatchmakingAgency();
void printDatabase();
};
#endif
MatchmakingAgency.cpp
#include "MatchmakingAgency.h"
MatchmakingAgency::MatchmakingAgency(){
nodeHead = nodeTail = NULL;
}
MatchmakingAgency::MatchmakingAgency(Client* data){
nodeHead = new Node(data);
}
MatchmakingAgency::~MatchmakingAgency(){
}
Node.cpp
#include "MatchmakingAgency.h"
MatchmakingAgency::Node::Node(){
next = NULL;
}
MatchmakingAgency::Node::Node(Client* data){
client = data;
next = NULL;
}
MatchmakingAgency::Node::Node(Client* data,Node* nextnode){
client = data;
next = nextnode;
}
希望你能帮助我,
并且请不要生气;)
非常感谢!
最佳答案
移动前向声明:
class Node;
从顶部进入
MatchmakingAgency
文件中的类MatchmakingAgency.h
。//class Node; << remove this
#include "Client.h"
#ifndef _MatchmakingAgency_H_
#define _MatchmakingAgency_H_
class MatchmakingAgency
{
private:
class Node; // << move here
Node* nodeHead;