Question: I have a class `Step` derived from `std::vector<unsigned int>`. I need to overload assignment operator because of the deep copy used in assignment of a value returned from a static method. I can't figur out how should I copy all elements of `rhv` to `this` in assignment:

```
class Step : public std::vector<unsigned int>
{
public:
    friend std::ostream& operator<<(std::ostream& outStream, const Step& step);
    Step& operator =(const Step& rhv);
    static Step fromString(const std::string &input);
    // Something like: Step x = Step::fromString("12 13 14 15 16");
private:
    double time;
    double pause;
    unsigned int id;
    std::string name;
};

```

and then overloading `=`:

```
Step& Step::operator =(const Step& rhv)
{
    time = rhv.time;
    pause = rhv.pause;
    id = rhv.id;
    // How should I copy contents of rhv to `this` safely?
    return *this;
}

```

Answer: 
I'm not 100% sure from your question, but I think you are asking about calling the parent `operator=`. In that case you have two options:

```
std::vector<unsigned int>::operator=(rhv); //either explicitly call the parent assignment op
*static_cast<std::vector<unsigned int>*>(this) = rhv; //or cast this to parentclass and call assignment on that

```

Of course in the code you have shown us you don't do any manual resource handling, so I don't see why you want to write your own assignment operator, the compiler generated one should do fine. Besides if you write your own assignment operator you might want to head the [rule of three](http://en.wikipedia.org/wiki/Rule_of_three_%28C++_programming%29) and write your own copy constructor and destructor too (at least in C++03, C++11 can be a bit different due to movable but not copyable classes).

As another sidenote: Most standardlibrary classes are not designed to be derived from, so you might want to rethink your design requiering you to inherit form `std::vector`
In this case you really don't have to overload `operator=` because the default generated one will work just fine (by assigning each member and base class in turn).

If you define your own operator, you can call the base class operator, just like you would call another base class function

```
std::vector<unsigned int>::operator=(rhv);

```

and let the vector handle its own assignment.