Jump to content
  • Advertisement
Sign in to follow this  
starstriker1

Creating class instances with variables

This topic is 4835 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Alright, I've got a function "AddObject(int type)" that takes types defined in an enum in one of my header files. From there, I have a large switch statement that creates an object based on the type given. I noticed, however, that the different cases all were handled the same way except for the TYPE of object they created with 'new', and the name of the object type created that I send to my log file. Is there a way I could get this type variable to select the proper class to create without a switch statement?

Share this post


Link to post
Share on other sites
Advertisement
if you descend these classes from a common ancestor, you can avoid the switch when creating them.

Tom#

Share this post


Link to post
Share on other sites
Sure, depending on what you're doing, either a simple template, or a more complex enum/functor map should provide such functionality. I can't say without knowing more about the requirements and limitations of what you're trying to engineer.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!