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. Solution for object identity

Solution for object identity

Scheduled Pinned Locked Moved C / C++ / MFC
c++questiondata-structurestutorial
2 Posts 2 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.
  • V Offline
    V Offline
    vmaltsev
    wrote on last edited by
    #1

    Hail, dear colleagues. I have a question about object identity. Let's say I need to make an array of some objects. These objects (classes) will be defined by users of the library. So, I have to provide a base class with an interface and create an array of these objects. It's clear. But when user creates a derived class and wants to get an object from the array, he should know about type of this object to be able to cast it back, because in this array objects of different types can be stored. So, the question is, how to define identity of derived class? Should I implement something like IsKindOf() method and use runtime identification, like in MFC, or there are other ways to do so? I have to mention that the only extension, which can be used, is STL. No MFC, nor any other platform depended libraries. Thank you in advance for any suggestions.

    J 1 Reply Last reply
    0
    • V vmaltsev

      Hail, dear colleagues. I have a question about object identity. Let's say I need to make an array of some objects. These objects (classes) will be defined by users of the library. So, I have to provide a base class with an interface and create an array of these objects. It's clear. But when user creates a derived class and wants to get an object from the array, he should know about type of this object to be able to cast it back, because in this array objects of different types can be stored. So, the question is, how to define identity of derived class? Should I implement something like IsKindOf() method and use runtime identification, like in MFC, or there are other ways to do so? I have to mention that the only extension, which can be used, is STL. No MFC, nor any other platform depended libraries. Thank you in advance for any suggestions.

      J Offline
      J Offline
      Johnny
      wrote on last edited by
      #2

      Hail to you too, comrade. The C++ standard provides something to solve this in the form of Run-Time Type Information (RTTI). For a starter you can look here[^]

      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