试图第一次创建链接列表

时间:2014-08-23 18:25:37

标签: c++ linked-list

首先我想说对不起,很确定问题会非常基本, 但这是我第一次尝试创建链表。

问题是当我尝试分配内存并在“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;
}

希望你能帮助我, 请不要生气;)

非常感谢!

2 个答案:

答案 0 :(得分:1)

移动前方声明:

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;

答案 1 :(得分:0)

看起来您必须始终使用完全限定名称:

MatchmakingAgency::Node::Node(Client* data,MatchmakingAgency::Node* nextnode){
    client = data;
    next = nextnode;
}