Home error C2244 unable to match function definition to an existing declaration in cpp /// operator overloading
Reply: 0

error C2244 unable to match function definition to an existing declaration in cpp /// operator overloading

user1990
1#
user1990 Published in April 27, 2018, 6:53 am

I am trying to overload =+ operator. there are two of it. One for the linkedlist+=linkedlist, other for the linkedlist+=templated type. But vs gives me an error.

template <class T>
const DList<T>& DList<T>::operator += (const DList & rhs)
{
    Node<T> temp=head;
while(temp->next!=NULL)
{
    temp=temp->next;
}

rhs.head->prev=temp;
temp->next=rhs.head;

return *this;
}

template <class T>
 DList<T>& DList<T>::operator += (T n)
 {

    Node<T> * temp= new Node<T>(n, NULL, head);

    head=temp;

return *this;
 }

Here the entire header:

#ifndef _DList_H
#define _DList_H


template <class T>

struct Node
{
T val;
Node<T>* next;
Node<T>* prev;
Node(T el, Node<T>* p=NULL, Node<T>* n=NULL ): val(el), prev(p), next(n) 
{};
};
template <class T>

 class DList
 {
 private:

 Node<T>* head;
 int size;


 public:
const DList & DList::operator += (const DList & rhs);


DList();
DList(const DList&);
~DList();
bool isEmpty();
void printList() const;
void addToBeginning(T n);
void deleteList ();

const DList<T> & DList::operator = (const DList & rhs);

const DList<T> & DList::operator += (T);
const DList<T> & DList::operator -= (T);
bool  DList<T>::operator < (const DList & rhs);
bool  DList<T>::operator > (const DList & rhs);
bool  DList<T>::operator == (const DList & rhs);
Node<T> * createClone () const;
};
#include "DList.cpp"  
#endif

Btw, it's my first question. I hope that asked it clearly and used the format correctly.

The full error message: Error 1 error C2244: 'DList::+=' : unable to match function definition to an existing declaration

+= operator used like this:

list4 += list1 += list2;

list1 -= 5;



 list1 -= 6;
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.329289 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO