Question: How do you set base class members using the assignment operator implementation? If for example someone defines the assignment operator in a derived class like this:

(where both `colour` and `Colour()` are members of the base class - meaning the lines indicated below are illegal)

```
Derived& Derived::operator=(const Derived& rhs) 
{
if (&rhs != this)
{

    Colour(rhs.colour);    // not allowed
        Colour(rhs.Colour());  // not allowed
}
return *this;
}

```

what is the solution? Is there a way of linking operator overloads in the base? Do I do something like...

```
Derived& Derived::operator=(const Derived& rhs) : Base::operator=(rhs)
...?

```

Answer: 
You're close, just put that call in the method body.

```
 if (&rhs != this)
 {
    Base::operator=(rhs);
    // ...

```
You should be able to use public accessors and mutators:

```
Derived& Derived::operator=(const Derived& rhs) 
{
   if (&rhs != this)
      SetColour(rhs.GetColour());
   return *this;
}

```

Otherwise make the members protected in the base class so that derived classes have access:

```
Derived& Derived::operator=(const Derived& rhs) 
{
   if (&rhs != this)
      colour = rhs.colour;
   return *this;
}

```

A third option could be to define an assignment operator public in the base class and have your derived class call the base operator:

```
Derived& Derived::operator=(const Derived& rhs) 
{
   if (&rhs != this)
      Base::operator=(rhs);
   return *this;
}

```

Here's a complete test case:

```
#define TEST 2
class Base
{
public:
    Base() : m_protected(0), m_private(0) {}
    Base(int pro, int pri) : m_protected(pro), m_private(pri) {}
    ~Base() {}

#if TEST == 1
    Base& operator=(const Base& rhs)
    {
        if (this != &rhs)
        {
            m_protected = rhs.m_protected;
            m_private = rhs.m_private;
        }

        return *this;
    }
#elif TEST == 2
    void SetPrivate(int i) { m_private = i; }
    int GetPrivate() const { return m_private; }
#endif

protected:
    int m_protected;
private:
    int m_private;
};

class Derived : public Base
{
public:
    Derived() : Base() {}
    Derived(int pro, int pri) : Base(pro, pri) {}
#if TEST == 1
    Derived& operator=(const Derived& rhs)
    {
        Base::operator=(rhs);
        return *this;
    }
#elif TEST == 2
    Derived& operator=(const Derived& rhs)
    {
        if (this != &rhs)
        {
            SetPrivate(rhs.GetPrivate());
            m_protected = rhs.m_protected;
        }
        return *this;
    }
#endif
};

int main()
{
    Derived a;
    Derived b(10, 5);

    a = b;
        return 0;
}

```