MFC DYNAMIC_DOWNCAST与dynamic_cast [英] MFC DYNAMIC_DOWNCAST vs. dynamic_cast
问题描述
MFC库中的DYNAMIC_DOWNCAST
和标准C ++ dynamic_cast
运算符之间有什么区别?可以将安全dynamic_cast
而不是DYNAMIC_DOWNCAST
用于MFC对象吗?
What is the difference between DYNAMIC_DOWNCAST
from MFC library and standard C++ dynamic_cast
operator? Can I use safety dynamic_cast
instead of DYNAMIC_DOWNCAST
for MFC objects?
当我的类包含DECLARE_DYNAMIC
和IMPLEMENT_DYNAMIC
宏时,我可以使用dynamic_cast
运算符还是必须对此类对象使用DYNAMIC_DOWNCAST
宏?
When my classes contain DECLARE_DYNAMIC
and IMPLEMENT_DYNAMIC
macros, can I use dynamic_cast
operator or I must use DYNAMIC_DOWNCAST
macro for this type of objects?
推荐答案
MFC库中的DYNAMIC_DOWNCAST与标准C ++ dynamic_cast运算符有什么区别?
What is the difference between DYNAMIC_DOWNCAST from MFC library and standard C++ dynamic_cast operator?
DYNAMIC_DOWNCAST和dynamic_cast通过不同的机制在运行时实现了相同的功能,即有关对象数据类型的信息. DYNAMIC_DOWNCAST通过使用一组宏来声明和实现用于获取对象的类信息的方法. dynamic_cast通过使用由编译器实现的运行时类型信息来实现相同的目的.
DYNAMIC_DOWNCAST and dynamic_cast achieve the same thing, information about an object's data type at runtime, through different mechanisms. DYNAMIC_DOWNCAST works through the use of a set of macros to declare and implement methods used to get the object's class information. dynamic_cast achieves the same thing through the use of Run-Time Type Information, which is implemented by the compiler.
我可以对MFC对象使用安全dynamic_cast而不是DYNAMIC_DOWNCAST吗? 当我的类包含DECLARE_DYNAMIC和IMPLEMENT_DYNAMIC宏时,我可以使用dynamic_cast运算符,还是必须对此类对象使用DYNAMIC_DOWNCAST宏?
Can I use safety dynamic_cast instead of DYNAMIC_DOWNCAST for MFC objects? When my classes contain DECLARE_DYNAMIC and IMPLEMENT_DYNAMIC macros, can I use dynamic_cast operator or I must use DYNAMIC_DOWNCAST macro for this type of objects?
如果使用RTTI进行编译并且至少具有一种虚拟方法,则允许使用dynamic_cast. DYNAMIC_DOWNCAST实现了许多虚拟方法,因此您只需要检查编译器是否支持RTTI并且已将其打开.
The use of dynamic_cast is allowed if you compile using RTTI and have at least one virtual method. DYNAMIC_DOWNCAST implements a bunch of virtual methods so you only have to check if your compiler supports RTTI and that it is turned on.
这篇关于MFC DYNAMIC_DOWNCAST与dynamic_cast的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!