Why assignment operators of parent class are not accessible from derived class objects

assignment-operator, c++, inheritance

Solution

The copy assignment operator is automatically generated in the derived class. This causes the base class's assignment operator to be hidden due to the regular name hiding rules of C++. You can unhide the name in the base class through the "using" directive. For example:

class C
{
  public:
    void operator =(int i) {}
};

class SubC : public C
{
  public:
    using C::operator=;
};

Problem

Example: ``` class C { public: void operator =(int i) {} }; class SubC : public C { }; ``` The following gives compilation error: ``` SubC subC; subC = 0; ``` "no match for 'operator=' in 'subC = 0'" Some sources state that it is because assignment operators are not inherited. But isn't it simply because default constructed copy-assignment of `SubC` overshadows them?

Original source