   get type of object?
  Hi! Is there some way I can get the type of an object and then use it to create a new instance of the object?What i'm attempting to do is to implement a way for my component manager to create components of specified types. In essence, all my components have a string ID and I want to be able to supply this ID to a function that will then return a pointer to a newly create component of the type that is associated to the ID.I can just make a switch-case to see if the ID matches any string and then just hard-code all the creation of these objects. But is there any other, better way to do it?One idea I had was to make the components register themselves in the component manager, but in that case I need to be able to get the type of that object and associate it with it's string ID.Am I making any sense?   
  What language are you writing in?It sounds like you want an abstract factory. However, it might be worth describing the actual purpose of this part of your design - there's a reasonably good chance you can accomplish the same result with a cleaner and less brittle piece of code.   ;  I'm using C++.What i'm trying to build is a component-based entity system for my game engine. Each entity contains a set of components that build up the actual game logic for that specific entity. Maybe you've heard of this approach before?EDIT: The abstract factory sounds pretty similar to what i'm looking for. I think i'll read some more about them. Thanks for the tip! :)[Edited by - DarkZoulz on June 15, 2006 4:13:53 PM];  I've heard of that approach, yes. What I'm not clear on is why you need to create new instances of the same class as a given object?   ;  Correct.one approach metaclassessentially dynamically allocate instance via typeidKuphryn   ;  Sorry if i'm not being clear. I'm not that good at explaining things.What i'm looking for is basicly a means to create instances of my component objects/classes without having to hard-code each one of my components into my createComponent() function.ex.IComponent *pResult = NULL;switch(componentID){    case "ACTOR":   pResult = new Component_Actor;   break;    case "NETWORK":   pResult = new Component_Network;   break;}return pResult;That's what my createComponent() function looks like now.Metaclasses and reflection sounds good too. I'll have to read up on them also.;  You could store "prototype" instances somewhere, and use a virtual constructor idiom. But the system still needs a way to get at the prototypes.Effectively, mapping a bit of text data (e.g. from a file) into an object type (and hence an instance of that object type) is a reflection task, whether you do it manually (e.g. building a std::map<std::string, IComponent*> to store your prototypes) or relying on built-in language stuff (C++ doesn't have any in the standard library, but Boost might be able to help you out).   