Dynamic creation of objects
-
Is it possible to build a string with a class name and then create a C++ object of that type using some kind of rtti?
-
Is it possible to build a string with a class name and then create a C++ object of that type using some kind of rtti?
like this? CBaseClass *pObj = NULL; file.ReadString(className); if (className == ClassA::SerializationName) pObj = new ClassA; else if (className == ClassB::SerializationName) pObj = new ClassB; -c ------------------------------ Smaller Animals Software, Inc. http://www.smalleranimals.com
-
Is it possible to build a string with a class name and then create a C++ object of that type using some kind of rtti?
Make your objects COM objects. This way you can look them up based on the ProgID. CLSIDFromProgID( L"ClassName", &clsid ); hr = CoCreateInstance( clsid, NULL, CLSCTX_ALL, __uuidof(IClass), (void **) &pIClass ); This has the benefit of not needing to do some big if statement and adding a new string every time a new class is added. Mike
-
Is it possible to build a string with a class name and then create a C++ object of that type using some kind of rtti?
You can pick some ideas from this article by Allen Holub: http://msdn.microsoft.com/library/periodic/period96/S385.htm Tomasz Sowinski -- http://www.shooltz.com.pl