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. Managed C++/CLI
  4. GetType for class

GetType for class

Scheduled Pinned Locked Moved Managed C++/CLI
questionhelp
6 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.
  • L Offline
    L Offline
    LionAM
    wrote on last edited by
    #1

    Hello! I want to compare the type of an object to a class. What is the correct syntax to use? In my case, I want to know if a control is an instance of MdiClient. GetType works on the pointer, but not on the class. typeid(MdiClient) gives me error C3767. Alex

    M 1 Reply Last reply
    0
    • L LionAM

      Hello! I want to compare the type of an object to a class. What is the correct syntax to use? In my case, I want to know if a control is an instance of MdiClient. GetType works on the pointer, but not on the class. typeid(MdiClient) gives me error C3767. Alex

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      if (some_ref_handle->GetType() == MdiClient::typeid)
      {
      //some_ref_handle references a MdiClient object!
      }

      L 1 Reply Last reply
      0
      • M Mark Salsbery

        if (some_ref_handle->GetType() == MdiClient::typeid)
        {
        //some_ref_handle references a MdiClient object!
        }

        L Offline
        L Offline
        LionAM
        wrote on last edited by
        #3

        Thank you! At first I got an error because MdiClient is a private(?) member of the class (which is not shown in the IntelliSense list). But with Windows::Forms::MdiClient::typeid it works. Alex

        M 1 Reply Last reply
        0
        • L LionAM

          Thank you! At first I got an error because MdiClient is a private(?) member of the class (which is not shown in the IntelliSense list). But with Windows::Forms::MdiClient::typeid it works. Alex

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          Cool :)

          LionAM wrote:

          MdiClient is a private(?) member of the class

          MdiClient IS the class.

          LionAM wrote:

          But with Windows::Forms::MdiClient::typeid it works.

          Oops - I guess I assumed "using namespace Windows::Forms;" typeid needs to know the type at compile time. You could also use something like

          if (some_ref_handle->GetType() == Type::GetType("Windows::Forms::MdiClient"))

          for a runtime check. Cheers, Mark

          L 1 Reply Last reply
          0
          • M Mark Salsbery

            Cool :)

            LionAM wrote:

            MdiClient is a private(?) member of the class

            MdiClient IS the class.

            LionAM wrote:

            But with Windows::Forms::MdiClient::typeid it works.

            Oops - I guess I assumed "using namespace Windows::Forms;" typeid needs to know the type at compile time. You could also use something like

            if (some_ref_handle->GetType() == Type::GetType("Windows::Forms::MdiClient"))

            for a runtime check. Cheers, Mark

            L Offline
            L Offline
            LionAM
            wrote on last edited by
            #5

            Hello! ::MdiClient::typeid works, but MdiClient::typeid gives error C3223: 'System::Windows::Forms::Form::MdiClient' : you cannot apply 'typeid' to a property Alex

            M 1 Reply Last reply
            0
            • L LionAM

              Hello! ::MdiClient::typeid works, but MdiClient::typeid gives error C3223: 'System::Windows::Forms::Form::MdiClient' : you cannot apply 'typeid' to a property Alex

              M Offline
              M Offline
              Mark Salsbery
              wrote on last edited by
              #6

              MdiClient is in the System::Windows::Forms namespace, not the System::Windows::Forms::Form namespace (which doesn't exist - System::Windows::Forms::Form is a class). Either of these should work:

              using namespace System::Windows::Forms;
              ...
              if (objectref->GetType() == MdiClient::typeid)

              or

              if (objectref->GetType() == System::Windows::Forms::MdiClient::typeid)

              Mark

              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