MFC and dynamic_cast?
-
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
-
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
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] -
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]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:
-
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
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
-
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
-
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:
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] -
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]According to my age, my memory doesn't go back that far ;P
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
According to my age, my memory doesn't go back that far ;P
Mark Salsbery Microsoft MVP - Visual C++ :java:
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] -
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]That was taken when I was 40.
Mark Salsbery Microsoft MVP - Visual C++ :java: