title: Overloading operators for adding two doubly linked lists
body: <p>I need help with overloading '+' operator for adding together two doubly linked lists. I cannot compile my program due to getting "no match for operator=..." error. I have overloaded '=' operator already but struggle to print the result of the addition to std output. I have also overloaded the &lt;&lt; operator. Been trying to figure out what is wrong for hours with no success. Any hints how to tackle this problem and/or solutions to it are very welcome. It is assignment for my OOP class.
  Thanks in advance!</p>
  
  <p>EDIT: The basic idea behind the code is to replicate set. Overloaded operators '+' should work as an union and '*' as intersection. I struggle to get the union properly printed to std output. '+=' seems to work fine. '&lt;&lt;' works good as well, but only when it comes to printing out single list.</p>
  
  <hr>
  
  <p>EDIT:
  Errors produced by compiler (g++, output from code::blocks, I have removed compiler notes):</p>
  
  <pre><code>llist3.cpp|149|error: no match for ‘operator=’ (operand types are ‘LList’ and ‘LList’)|
  llist3.cpp|106|note:   no known conversion for argument 1 from ‘LList’ to ‘LList&amp;’|
  llist3.cpp|151|error: no match for ‘operator=’ (operand types are ‘LList’ and ‘LList’)|
  llist3.cpp|106|note:   no known conversion for argument 1 from ‘LList’ to ‘LList&amp;’|
  llist3.cpp|152|error: no match for ‘operator&lt;&lt;’ (operand types are ‘std::ostream {aka       std::basic_ostream&lt;char&gt;}’ and ‘LList’)|
  </code></pre>
  
  <hr>
  
  <pre><code>   #include&lt;iostream&gt;
  using namespace std;
  
  class LList {
  public:
      struct Node {
          int elem;
          Node* succ;
          Node* prev;
          Node() : succ(0), prev(0), elem(0) {}
      };
      LList();
      LList(LList&amp; list);
      ~LList();
  
      Node* next();
      Node* begin()  { curr = head; }
  
      int getElem() { return curr-&gt;elem; }
      void addElem(int elem);
      LList operator+(LList&amp; set);
      LList operator+(int elem);
      LList&amp; operator+=(LList&amp; set);
      LList&amp; operator+=(int elem);
      LList&amp; operator=(LList&amp; list);
      friend ostream&amp; operator&lt;&lt;(ostream&amp; os, LList&amp; obj);
   private:
      Node* curr;
      Node* head;
      Node* tail;
      int size;
      void pushFront(Node* n);
      void pushInside(Node* n);
      void pushBack(Node* n);
  };
  
  LList::LList() : head(0), tail(0), size(0), curr(0) {}
  LList::LList(LList&amp; list) : size(0), curr(0), head(0), tail(0) {
      list.curr = list.head;
      while(list.curr) {
          addElem(list.getElem());
          list.next();
      }
  }
  LList::Node* LList::next() {
      if (curr)
          return (curr = curr-&gt;succ);
      else
          return 0;
  }
  void LList::addElem(int elem) {
      Node* n = new Node;
      n-&gt;elem = elem;
      if (curr) {
          if (curr == head &amp;&amp; elem &lt; curr-&gt;elem) {
              pushFront(n);
          }
          else if (elem &gt; curr-&gt;elem) {
              curr = curr-&gt;succ;
              addElem(elem);
          }
          else if (elem &lt; curr-&gt;elem &amp;&amp; elem &gt; (curr-&gt;prev)-&gt;elem) {
              pushInside(n);
          }
          else if (elem &lt; curr-&gt;elem) {
              curr = curr-&gt;prev;
              addElem(elem);
          }
      } else {
          pushBack(n);
      }
  }
  void LList::pushFront(Node* n) {
      head = n;
      n-&gt;succ = curr;
      curr-&gt;prev = n;
      n-&gt;prev = 0;
      curr = n;
      size++;
  }
  void LList::pushInside(Node* n) {
      (curr-&gt;prev)-&gt;succ = n;
      n-&gt;succ = curr;
      n-&gt;prev = curr-&gt;prev;
      curr-&gt;prev = n;
      size++;
  }
  void LList::pushBack(Node* n) {
      if (!head) {
          head = n;
      } else {
          tail-&gt;succ = n;
          n-&gt;prev = tail;
      }
      tail = n;
      curr = n;
      size++;
  }
  LList::~LList() {
      for (curr = head; curr;) {
          Node* temp = curr-&gt;succ;
          delete curr;
          curr = temp;
      }
  }
  LList&amp; LList::operator=(LList&amp; list) {
      list.begin();
      if (this != &amp;list) {
          for (curr = head; curr;) {
              Node* temp = curr-&gt;succ;
              delete curr;
              curr = temp;
          }
          while (list.curr) {
              addElem(list.getElem());
              list.next();
          }
      }
      return *this;
  }
  ostream&amp; operator&lt;&lt;(ostream&amp; os, LList&amp; list) {
      LList::Node* p = list.head;
      os &lt;&lt; "{ ";
      while(p) {
          os &lt;&lt; p-&gt;elem &lt;&lt; (p-&gt;succ ? ", " : "");
          p = p-&gt;succ;
      }
      os &lt;&lt; " }" &lt;&lt; endl;
      return os;
  }
  LList LList::operator+(LList&amp; set) {
      LList temp = *this;
      temp += set;
      return temp;
  }
  LList LList::operator+(int elem) {
      *this += elem;
      return *this;
  }
  int main() {
      LList setA;
      setA.addElem(1234);
      setA.addElem(1435);
      setA.addElem(1100);
      LList setB;
      setB.addElem(1234);
      setB.addElem(1435);
      setB.addElem(5100);
      setB = setA + 1234; // 1st error here
      LList setD;
      setD = setA + setB; //2nd
      cout &lt;&lt; setA + setB &lt;&lt; endl; //3rd
  }
  </code></pre>