[Solved] Difference between vector and Derived vector class


In the first case, Derived is a class which can be used to declare a variable. In the second Derived is a variable name of type std::vector<Base>.

In the case of the class it is possible to produce undefined behaviour with the following code:

void deleter(std::vector<Base>* ptr)
{
    delete ptr;
}


void buggy()
{
    auto ptr = new Derived();
    // ... operations on ptr.
    deleter(ptr);   // Oops.
}

The problem is that std::vector doesn’t have a virtual destructor, so the
deletion is undefined behaviour.

solved Difference between vector and Derived vector class