title: Can we use delete on the reference (not the pointer) in a range-for loop?
body: <p>I am using an object factory with a function to create and register new objects :</p>
  
  <pre><code>Object * MyObjectFactory::createNewObject()
  {
     Object * my_object = new Object();
     m_vector_of_objects.push_back(my_object);
  
     return my_object;
  }
  </code></pre>
  
  <p>I am now writing the delete operator, where I just loop through the vector and delete all the objects, and I am wondering if there is a difference between :</p>
  
  <pre><code>MyObjectFactory::~MyObjectFactory()
  {
     // Destroy memory allocated objects
     for (auto * my_object : m_vector_of_objects)
     {
        delete(my_object);
     }
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>MyObjectFactory::~MyObjectFactory()
  {
     // Destroy memory allocated objects
     for (auto &amp;my_object : m_vector_of_objects)
     {
        delete(my_object);
     }
  }
  </code></pre>
  
  <p>Is it actually de-allocating memory in both case ?</p>