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. how to get variable type

how to get variable type

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
24 Posts 9 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.
  • C closecall

    yes i am using vc++6.0 i will try the typeid method once i re-write all my lost codes :| My initial intention was to come up with a global class that can convert a variable of type A to type B at run-time.

    M Offline
    M Offline
    Mahendra_786
    wrote on last edited by
    #21

    What vc 7.x is doing seems more logical than vc 6.0 ... it seems to be checking the "from" and "to" types! class A { int a; }; class B: public A { int b; }; /***** break ****/ B b; if (dynamic_cast**(&b)) { printf("OK"); } /***** above will work in vc 7.x but not vc 6.0 */ /***** below will NOT work in both vc 7.x & vc 6.0 */ B b; A *p_a = &b; if (dynamic_cast**(p_a)) { printf("OK"); }****

    1 Reply Last reply
    0
    • C closecall

      is it possible to check a variable's type? e.g. if m_variable is equal to CString, DoSomething()...

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #22

      did you try **typeid**() ??:-D


      TOXCCT >>> GEII power

      1 Reply Last reply
      0
      • C closecall

        is it possible to check a variable's type? e.g. if m_variable is equal to CString, DoSomething()...

        A Offline
        A Offline
        Anthony_Yio
        wrote on last edited by
        #23

        For non RTTI way You could try IsKindOf (Of course, this is not as good as RTTI. As this was invented by Microsoft before the time where RTTI was approved by ANSI.) For RTTI you could try type_info or the one they mentiond dynamic_cast.. Sonork 100.41263:Anthony_Yio Life is about experiencing ...

        1 Reply Last reply
        0
        • C closecall

          is it possible to check a variable's type? e.g. if m_variable is equal to CString, DoSomething()...

          D Offline
          D Offline
          David Crow
          wrote on last edited by
          #24

          For MFC objects, have you looks at IsKindOf()?


          "The pointy end goes in the other man." - Antonio Banderas (Zorro, 1998)

          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