title: C++: Replacing Long Switch() Statement with Indexed Array?
body: <p>To create a game object dynamically, I take the <strong>ObjectTypeID</strong>, which is <strong>unsigned int</strong>, and let it compare within very long <strong>switch()</strong> statement. If the appropriate swith case is found, I create the object and store it. Because I already have 90 Game Objects, the Switch() is already very long and will be growing to about 300 objects.</p>
  
  <p>To avoid the extra long switch() statement, and to improve speed, the perfect candidate would be taking advantage of indexed array to store all the object types (ObjectTypeID increases from 0 upward). <strong>Is there a way, how to store Object Type within an array?</strong></p>
  
  <p>I would like to use something like this:     </p>
  
  <ul>
  <li><strong>aObjectTypesArray[ObjectTypeID] *pNewDynamicObject = new aObjectTypesArray[ObjectTypeID];</strong></li>
  </ul>
  
  <p>Can you advise me, please, how to take advantage of dynamic array indexing in my case, and how to avoid extra long switch() statement? Your advice might differ from my idea, the key is to use array indexing and to remove long switch() statement.</p>