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. IsKindOf detection

IsKindOf detection

Scheduled Pinned Locked Moved C / C++ / MFC
question
3 Posts 3 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
    LighthouseJ
    wrote on last edited by
    #1

    I have a class called CFileObject derived from CObject and a class called CFileTree derived from CObList. At a particular point in my program, I have an if statement that tests if an object (could be a CFileObject or CFileTree) is a CFileObject. At a point in the execution, the object is a CFileTree but when it runs the test, it returns true, saying it's a CFileObject which is incorrect. Do I need to declare my two types as being the types that they are so IsKindOf() can resolve properly?

    R S 2 Replies Last reply
    0
    • L LighthouseJ

      I have a class called CFileObject derived from CObject and a class called CFileTree derived from CObList. At a particular point in my program, I have an if statement that tests if an object (could be a CFileObject or CFileTree) is a CFileObject. At a point in the execution, the object is a CFileTree but when it runs the test, it returns true, saying it's a CFileObject which is incorrect. Do I need to declare my two types as being the types that they are so IsKindOf() can resolve properly?

      R Offline
      R Offline
      Ravi Bhavnani
      wrote on last edited by
      #2

      From the MSDN documentation[^]: "This function works only for classes declared with the DECLARE_DYNAMIC, DECLARE_DYNCREATE, or DECLARE_SERIAL macro. Do not use this function extensively because it defeats the C++ polymorphism feature. Use virtual functions instead." /ravi My new year's resolution: 2048 x 1536 Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com

      1 Reply Last reply
      0
      • L LighthouseJ

        I have a class called CFileObject derived from CObject and a class called CFileTree derived from CObList. At a particular point in my program, I have an if statement that tests if an object (could be a CFileObject or CFileTree) is a CFileObject. At a point in the execution, the object is a CFileTree but when it runs the test, it returns true, saying it's a CFileObject which is incorrect. Do I need to declare my two types as being the types that they are so IsKindOf() can resolve properly?

        S Offline
        S Offline
        S Senthil Kumar
        wrote on last edited by
        #3

        You could try using dynamic_cast instead. But as Ravi said, it's not good OO practice. Regards Senthil _____________________________ My Blog | My Articles | WinMacro

        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