title: How do I declare an overloaded operator in an abstract class and override it in a derived non-abstract class?
body: <p>I'm trying to write an abstract class with some pure virtual binary operators, which should be implemented by the derived class in order to accomplish operator polymorphism. Here's a simplified example:</p>
  
  <pre><code>class Base {
  public:
      virtual const Base&amp; operator+ (const Base&amp;) const = 0;
  };
  
  class Derived : public Base {
  public:
      const Derived&amp; operator+ (const Derived&amp;) const;
  };
  
  const Derived&amp; Derived::operator+ (const Derived&amp; rvalue) const {
      return Derived();
  }
  </code></pre>
  
  <p>It doesn't matter right now what the operator does, the important part is what it returns: it returns a temporary Derived object, or a reference to it. Now, if I try to compile, I get this:</p>
  
  <pre><code>test.cpp: In member function ‘virtual const Derived&amp; Derived::operator+(const Derived&amp;) const’:
  test.cpp:12:17: error: cannot allocate an object of abstract type ‘Derived’
  test.cpp:6:7: note:   because the following virtual functions are pure within ‘Derived’:
  test.cpp:3:22: note:    virtual const Base&amp; Base::operator+(const Base&amp;) const
  </code></pre>
  
  <p>What's wrong? Isn't operator+ (the only pure virtual function in Base) being overriden? Why should Derived be abstract as well?</p>