首先我想说我很抱歉,很确定这个问题将是非常基本的,但这是我第一次尝试创建一个链表。
问题是当我尝试分配内存并在"nodeHead"内放置一个新的节点地址时,我得到一个错误说:
错误C2440: '=':无法从'MatchmakingAgency::Node *'转换为'Node *'
智能感知:类型为"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.h
文件中的MatchmakingAgency
类
//class Node; << remove this
#include "Client.h"
#ifndef _MatchmakingAgency_H_
#define _MatchmakingAgency_H_
class MatchmakingAgency
{
private:
class Node; // << move here
Node* nodeHead;
看起来您必须在使用完全限定名称时保持一致:
MatchmakingAgency::Node::Node(Client* data,MatchmakingAgency::Node* nextnode){
client = data;
next = nextnode;
}