I'm reading the documentation of vector. Here I found that:
~vector();callsallocator_traits::destroyon each of the contained elements, and deallocates all the storage capacity allocated by the vector using its allocator.
I don't understand how can you delete an element without deallocating it.
Going further with destroy (allocator_type& alloc, T* p); :
Destroys the element object pointed by p without deallocating its storage. In the non-specialized definition of
allocator_traits, this member function callsalloc.destroy(p)if such a call is well formed. Otherwise, it invokesp->~T().
- I don't understand what they mean by destroy the element without deallocating its storage (again).
- How would this involve p->~T()if myvector<T> obj {T(), T()}consists of automatically objects, not pointers?
- How could it call destroyon aT**if my vector isvector<T*>...?
I'm trying to do a parallel between calling the destructor on objects like:
- MyClass obj()respectively
- MyClass obj = new MyClass()
vs
- vector<T> obj {T(), T()}
- vector<T*> obj {new T(), new T()}
and I can't see how they are similar, because they should be as one contains the other.
 
     
     
     
    