2
The builders move and copy are only called in the creation of an object? if yes, after the creation of an object, it is not possible to call either explicitly or implicitly the move or copy constructor of that object, right? The doubt arose from here:
class Engine
{
public:
Engine(int length) : m_size(length), m_ptr(new int[length])
{
}
~Engine()
{
delete[] m_ptr;
}
Engine(const Engine& e) : m_ptr(new int[e.m_size])
{
this->m_size = e.m_size;
*this->m_ptr = *e.m_ptr;
}
private:
int* m_ptr;
int m_size;
};
As we can see, when the constructor is called, it allocates space in the heap pro m_ptr
. So if somehow the copy constructor was called after that,
it would re-allocate memory in m_ptr
and previously allocated memory would be leaked.
I am almost sure of the answer, but as I have never seen any explicit mention of it, I leave my doubt here.