Ce face operatorul dynamic_cast?

Intrebari despre limbajul C++, standardul C++, STL, OOP in C++ sau alte subiecte nelegate de VisualC++
Post Reply
User avatar
MrSmersh
Microsoft MVP
Microsoft MVP
Posts: 289
Joined: 20 Jul 2007, 10:18
Location: Timisoara
Contact:

Ce face operatorul dynamic_cast?

Post by MrSmersh » 12 Aug 2011, 22:31

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 ]



User avatar
Ovidiu Cucu
Fondator
Fondator
Posts: 3778
Joined: 11 Jul 2007, 16:10
Judet: Iaşi
Location: Iasi
Contact:

Re: Ce face operatorul dynamic_cast?

Post by Ovidiu Cucu » 13 Aug 2011, 09:12

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

Post Reply