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. MFC and dynamic_cast?

MFC and dynamic_cast?

Scheduled Pinned Locked Moved C / C++ / MFC
c++debuggingquestionannouncement
9 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.
  • N Offline
    N Offline
    nobaq
    wrote on last edited by
    #1

    Hello, Is there any reason why dynamic_cast<> is turned off in my MFC projects by default? I always get (in Debug and Release builds).

    warning C4541: 'dynamic_cast' für polymorphen Typ 'CWnd' mit /GR- verwendet; unvorhersehbares Verhalten möglich

    Is there any reason to not add the /GR switch? Why is this not done by default? The whole C-style casting with objects in the MFC code itself is really bad coding style anyway (C-style casts should not be used any more in C++) Regards, Niki

    C J 2 Replies Last reply
    0
    • N nobaq

      Hello, Is there any reason why dynamic_cast<> is turned off in my MFC projects by default? I always get (in Debug and Release builds).

      warning C4541: 'dynamic_cast' für polymorphen Typ 'CWnd' mit /GR- verwendet; unvorhersehbares Verhalten möglich

      Is there any reason to not add the /GR switch? Why is this not done by default? The whole C-style casting with objects in the MFC code itself is really bad coding style anyway (C-style casts should not be used any more in C++) Regards, Niki

      C Offline
      C Offline
      CPallini
      wrote on last edited by
      #2

      What about documentation [^]? It looks like you're using Visual Studio 2003 or earlier. :)

      If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
      This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
      [My articles]

      M 1 Reply Last reply
      0
      • C CPallini

        What about documentation [^]? It looks like you're using Visual Studio 2003 or earlier. :)

        If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
        This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
        [My articles]

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

        Heh. I was wondering how old the Visual Studio version had to be. I can't remember the last time RTTI wasn't enabled by default.

        Mark Salsbery Microsoft MVP - Visual C++ :java:

        C 1 Reply Last reply
        0
        • N nobaq

          Hello, Is there any reason why dynamic_cast<> is turned off in my MFC projects by default? I always get (in Debug and Release builds).

          warning C4541: 'dynamic_cast' für polymorphen Typ 'CWnd' mit /GR- verwendet; unvorhersehbares Verhalten möglich

          Is there any reason to not add the /GR switch? Why is this not done by default? The whole C-style casting with objects in the MFC code itself is really bad coding style anyway (C-style casts should not be used any more in C++) Regards, Niki

          J Offline
          J Offline
          Jijo Raj
          wrote on last edited by
          #4

          For determining class relations at runtime, MFC have its own mechanism called RTCI(Runtime Class Information) which is similar to RTTI in C++. You can resolve class relations by using CRuntimeClass::IsKindOf() etc. [Edit] With respect to Pillani's reply. So its obvious that C++ RTTI will be switch offed by default, since MFC itself is providing support. Enabling two similar stuffs at same time helps only to reduce performance. :) I'm not sure, but i think that the RTCI evolved and exists together with RTTI due to historic reasons. Regards, Jijo.

          _____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.

          modified on Monday, January 5, 2009 5:12 PM

          N 1 Reply Last reply
          0
          • J Jijo Raj

            For determining class relations at runtime, MFC have its own mechanism called RTCI(Runtime Class Information) which is similar to RTTI in C++. You can resolve class relations by using CRuntimeClass::IsKindOf() etc. [Edit] With respect to Pillani's reply. So its obvious that C++ RTTI will be switch offed by default, since MFC itself is providing support. Enabling two similar stuffs at same time helps only to reduce performance. :) I'm not sure, but i think that the RTCI evolved and exists together with RTTI due to historic reasons. Regards, Jijo.

            _____________________________________________________ http://weseetips.com[^] Visual C++ tips and tricks. Updated daily.

            modified on Monday, January 5, 2009 5:12 PM

            N Offline
            N Offline
            nobaq
            wrote on last edited by
            #5

            Thank you very much, I've enabled it now and use dynamic_cast. Yes, I habe VS 2003 .NET. Niki

            1 Reply Last reply
            0
            • M Mark Salsbery

              Heh. I was wondering how old the Visual Studio version had to be. I can't remember the last time RTTI wasn't enabled by default.

              Mark Salsbery Microsoft MVP - Visual C++ :java:

              C Offline
              C Offline
              CPallini
              wrote on last edited by
              #6

              According to documentation [^] Visual Studio 2003 is old enough. :)

              If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
              This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
              [My articles]

              M 1 Reply Last reply
              0
              • C CPallini

                According to documentation [^] Visual Studio 2003 is old enough. :)

                If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                [My articles]

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

                According to my age, my memory doesn't go back that far ;P

                Mark Salsbery Microsoft MVP - Visual C++ :java:

                C 1 Reply Last reply
                0
                • M Mark Salsbery

                  According to my age, my memory doesn't go back that far ;P

                  Mark Salsbery Microsoft MVP - Visual C++ :java:

                  C Offline
                  C Offline
                  CPallini
                  wrote on last edited by
                  #8

                  According to the photograph in your CodeProject member's page, you're not that old. :rolleyes:

                  If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                  This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                  [My articles]

                  M 1 Reply Last reply
                  0
                  • C CPallini

                    According to the photograph in your CodeProject member's page, you're not that old. :rolleyes:

                    If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
                    This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
                    [My articles]

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

                    That was taken when I was 40.

                    Mark Salsbery Microsoft MVP - Visual C++ :java:

                    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