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

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

Ali Osman Berk
1#
Ali Osman Berk Published in 2017-12-07 21:10:12Z

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;
Sebastian Martin Dicke
2#
Sebastian Martin Dicke Reply to 2017-12-07 21:36:33Z

It could be helpful if you post the full error message produced by your compiler to understand the problem.

Sebastian Martin Dicke
3#
Sebastian Martin Dicke Reply to 2017-12-07 22:01:20Z

If you are using templates, you cannot separate function defintion from declaration.

The DList:: prefix may not be in the function declaration within the class body.

You should not inculde cpp files. These files should include header files to make declarations available for the compiler.

You need to login account before you can post.

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

© 2016 Powered by mzan.com design MATCHINFO