Page 1 of 1

Ce face operatorul dynamic_cast?

Posted: 12 Aug 2011, 22:31
by MrSmersh
In drumul meu spre un ban sau o bere :biggrin:
Eu as incerca sa pun in imagine si operatorii MFC din zona asta si macrourile DYNAMIC_DOWNCAST si STATIC_ sa vedem care e treaba cu ei... Asa dpv didactic

[ continuare din topicul de la FAQ, Tips & Tricks: http://www.codexpert.ro/forum/viewtopic.php?f=29&t=1829 ]

Re: Ce face operatorul dynamic_cast?

Posted: 13 Aug 2011, 09:12
by Ovidiu Cucu
MrSmersh wrote:In drumul meu spre un ban sau o bere :biggrin:
Eu as incerca sa pun in imagine si operatorii MFC din zona asta si macrourile DYNAMIC_DOWNCAST si STATIC_ sa vedem care e treaba cu ei... Asa dpv didactic
In mod sigur am fi in drumul spre o bere daca, de exemplu, m-ai ajuta sa traduc, nu mot à mot ci pe intelesul tuturor ce zic Sfintii Parinti in Scriptura. :biggrin:
ISO/IEC 14882:2003
5.2.7 Dynamic cast
The run-time check logically executes as follows:
— If, in the most derived object pointed (referred) to by v, v points (refers) to a public base class subobject of a T object, and if only one object of type T is derived from the sub-object pointed (referred) to by v, the result is a pointer (an lvalue referring) to that T object.
— Otherwise, if v points (refers) to a public base class sub-object of the most derived object, and the type of the most derived object has a base class, of type T, that is unambiguous and public, the result is a pointer (an lvalue referring) to the T sub-object of the most derived object.
— Otherwise, the run-time check fails.
sau, parca un pic mai clar formulat in draft-ul C++0x
5.2.7 Dynamic cast
8. If C is the class type to which T points or refers, the run-time check logically executes as follows:
— If, in the most derived object pointed (referred) to by v, v points (refers) to a public base class subobject of a C object, and if only one object of type C is derived from the subobject pointed (referred) to by v the result points (refers) to that C object.
— Otherwise, if v points (refers) to a public base class subobject of the most derived object, and the type of the most derived object has a base class, of type C, that is unambiguous and public, the result points (refers) to the C subobject of the most derived object.
— Otherwise, the run-time check fails.
T si v sunt din expresia dynamic_cast<T>(v).


Cat despre macro-urile MFC, DYNAMIC_DOWNCAST s.a.m.d. eu cred ca le-ar sta bine intr-un topic separat din sectiunea dedicata, [MFC] FAQ, Tips & Tricks, in loc sa le adaugam la topcul acela din [C++] FAQ, Tips & Tricks, zic eu, si-asa destul de naspa despre ceva care multi folosesc, putini stiu cum, si mai putini stiu de ce. ;)

Well, astept cu placere in continuare sugestii, corecturi si completari.
Pana atunci, ma duc sa comand o lada cu bere. :D