What is the reason that `std::exception` is designed in a way that to create a new type of exception, A derived class is made which overrides the `virtual what()` function, than make a class that could hold a string and return that on `what()`?

```
class exception
{
    std::string msg;
public:
    exception(std::string _msg) : msg(_msg) {}
    void set(std::string _msg) { msg = _msg; }
    std:string what() { return msg; }
};

```

And each error `(bad_alloc, logical_error ...)` could be an instance of the class rather than a derived class.

What is the reason that virtual functions and inheritance is used rather than the above approach ?