3

Please see this code fragment:

class Base {
public:
    const Base& foo      (const int&);
    const Base& operator=(const int&);
};

class Derived : public Base {};

void fn() {
    Derived   c;

    c.foo(3);  // compiles fine (as expected)
    c = 3;     // error: no match for ‘operator=’
}

The question is why is operator= not inherited from Base to Derived just like foo() is?

Is there something in the standard that makes operator= special with respect to inheritance?

Thanks

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953
  • 1
    So, the standard link; http://eel.is/c++draft/over.ass#1; and to fix it (if not known); add a using to bring the operator into scope, `class Derived : public Base { public: using Base::operator=; };` – Niall Jul 12 '16 at 12:23
  • 1
    Umm doesn't the linked question treat about copy assignment operator? I.e. in a form of `T& operator=(const T&)`, here we have and `int` as an argument. No one explains that every possible assingment operator is created implicitly. It that true? – luk32 Jul 12 '16 at 12:24

0 Answers0