jeudi 5 novembre 2020

How to write setters and getters for a doubly linked list in c++

When I try to write getNext() method in Node.cpp it gives the below error. Please check in Node.cpp getNext() method.I am trying to write getters and setters for a doubly linked list and here is what i have.

class Node

{

    private:

        string phonenumber;
        string name;
        string type;
        Node* next;
        Node* prev;

    public:
        Node(string name, string phonenumber, string type);

        void setNext(Node ptr);
        Node getNext();

        string getName();
        void setName(string name);


        string getPhone();
        void setPhone(string phonenum);


        string getType();
        void setType(string type);

};
#endif

Node.cpp

    #include "Node.h"
    
    Node::Node(string name, string phonenumber, string type)
    {
       //constructor
    }
    
    Node::Node(string name, string phonenumber, string type)
    {
    
    }
    void Node::setNext(Node ptr)
    {
        
    
    }

When I try to write getNext() method in Node.cpp it gives the below error. Please check in Node.cpp getNext() method.I am trying to write getters and setters for a doubly linked list and here is what i have.

    Node Node::getNext()
    {
    
       return next; /**/ this line gives me an error (it says no suitable constructor exists for Node* to Node)
    }

Aucun commentaire:

Enregistrer un commentaire