title: C++ Initializing an Array of Objects
body: <p>I'm having a little trouble grasping some concepts with C++ arrays.</p>
  
  <ol>
  <li><p>On my assignment, I did something like the code below. From what I can tell, this not only creates space on the heap for [size] Object1 objects, but also initializes all of them too. Can somebody explain what is exactly happening on the heap and stack here?</p>
  
  <pre><code>class Object1
  {
    Private:
      int dummy;
    Public:
      Object1();
  };
  
  Object1::Object1()
  {
    dummy = 1;
  }
  
  class Foo
  {
    private:
      Object1 * myObject;
  
    public:
      Foo(int size);
  };
  
  Foo::Foo(int size)
  {
    myObject = new Object1[size];
  }
  </code></pre></li>
  <li><p>If Object1's constructor had taken a parameter, like in the code below, then what would happen differently on the stack and heap, if anything? I'm not sending any parameters into each instance of object1, so would it still initialize any object, or just create the space?</p>
  
  <pre><code>class Object1
  {
    Private:
      int dummy;
    Public:
      Object1(int myInt);
  };
  
  Object1::Object1(int myInt)
  {
    dummy = myInt;
  }
  </code></pre></li>
  <li><p>I also saw the code below somewhere. What is happening in this case, and how is it different than the cases above?</p>
  
  <pre><code>myclass *array[10];
  for (int i = 0 ; i != 10 ; i++) {
      array[i] = new myclass();
  }
  </code></pre></li>
  </ol>
  
  <p>I've completed the assignment, but am just trying to make sure I understand what's happening behind the scenes.</p>
  
  <p>Thank you in advance for taking the time to help!</p>