5

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?

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?

rgb
  • 1,750
  • 1
  • 20
  • 35
  • possible duplicate of [Why is DECLARE\_DYNAMIC & IMPLEMENT\_DYNAMIC nessary for DYNAMIC\_DOWNCAST?](http://stackoverflow.com/questions/14318993/why-is-declare-dynamic-implement-dynamic-nessary-for-dynamic-downcast) – Richard Critten Mar 13 '15 at 12:59
  • 1
    @RichardCritten Indicated post does not contain answer for my question. – rgb Mar 13 '15 at 21:49

1 Answers1

8

What is the difference between DYNAMIC_DOWNCAST from MFC library and standard C++ dynamic_cast operator?

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.

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?

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.