title: C++ Initialize object member of a struct that is allocated using the "new" keyword
body: <p>This may be a complicated question but I assume it has a simple answer.</p>
  
  <p>So I have a struct that contains custom object types:</p>
  
  <pre><code>// header1.h
  
  struct MyStruct
  {
      MyClass myObject1;
      MyClass myObject2;
  };
  </code></pre>
  
  <p>And I have a global pointer to a MyStruct. I am going to allocate and instantiate the struct using the <code>new</code> keyword. When I do so, I want to construct each myObject by name in an initializer list, as shown below.</p>
  
  <pre><code>// codeFile1.cpp
  
  MyStruct *myStructPtr;
  
  int main()
  {
      myStructPtr = new MyStruct
      {                                     //syntax error: missing ';'
          .myObject1 = MyClass(arg1, arg2),
          .myObject2 = MyClass(arg1, arg2)
      };
  }
  </code></pre>
  
  <p>The code snippet above has syntax errors, but it demonstrates what I want to do. Note that MyClass does not have a default constructor, so it must be given an argument list.</p>
  
  <p>Thanks!</p>
  
  <p><strong>EDIT - CONCLUSION</strong></p>
  
  <p>As pointed out, my initialization list is C-style, which fails to work. Unfortunately the C++11 initializer-list does not meet my compiler requirements, and the option of throwing all arguments into a constructor is not practical.</p>
  
  <p>So I took an alternative solution and changed the pointer structure to the following:</p>
  
  <pre><code>// header1.h
  
  struct MyStruct
  {
      MyClass *myObjectPtr1;
      MyClass *myObjectPtr2;
  };
  
  // codeFile1.cpp
  
  MyStruct myStruct;
  
  int main()
  {
      myStructPtr.myObjectPtr1 = new MyClass(arg1, arg2);
      myStructPtr.myObjectPtr2 = new MyClass(arg1, arg2);
  }
  </code></pre>
  
  <p>Thanks all!</p>