Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Dynamic creation of objects

Dynamic creation of objects

Scheduled Pinned Locked Moved C / C++ / MFC
c++question
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Luis Barreira
    wrote on last edited by
    #1

    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?

    C M T 3 Replies Last reply
    0
    • L Luis Barreira

      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?

      C Offline
      C Offline
      Chris Losinger
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • L Luis Barreira

        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?

        M Offline
        M Offline
        MikeG 0
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • L Luis Barreira

          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?

          T Offline
          T Offline
          Tomasz Sowinski
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups