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: 
Inheriting from standard containers is generally considered a bad idea because they aren't designed to be used as base classes (no virtual destructor among other things). Composition is preferred in pretty much every case.

Assuming you've decided to step into this minefield, you can invoke the parent assignment operator with a `static_cast`.

`*static_cast<std::vector<unsigned int>*>(this) = rhv;`

and don't forget to assign `name` as well.
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.