Convert 'const std :: string' to 'std :: string &'

0

I have an error and would like tips to solve it

I have my Node struct inside the DLList class:

struct Node
{
    Type m_data;
    Node *m_next, *m_prev;

    Node(Type& v, Node* _prev) : m_data(v), m_prev(_prev), m_next(nullptr) {}
};

Node *m_head, *m_tail;
int m_size;

And the function:

template<typename Type>
void DLList<Type>::addHead(const Type& v)
{
    Node* node = new Node(v, m_head);

    node->m_data = v;
    node->m_next = m_head;
    m_head = node;

    ++m_size;
}

But when creating the Node * node passing the parameters, the compiler is returning this error: : can not convert argument 1 from 'const std :: string' to 'std :: string &'

The parameters passed, are coming from main ():

DLList<string> list;
DLList<string> list2;
DLList<string>* list3;
DLLIter<string> iter(list);
DLList<int>* testPointer;
    
asked by anonymous 09.02.2016 / 20:49

1 answer

0

I just found the error ... Lack of attention at all.

My Node builder is ready to receive only 'Type & v ', while I'm trying to pass' const Type & v ', which logically would not work.

New struct Node:

struct Node
{
    Type m_data;
    Node *m_next, *m_prev;

    Node(const Type& v, Node* _prev) : m_data(v), m_prev(_prev), m_next(nullptr)    {}
};
    
09.02.2016 / 21:03