James Rogers wrote in message news:... > kanze@gabi-soft.fr wrote in > news:d6652001.0306180239.2b9672c8@posting.google.com: > > I don't know about controlled types, so I can't say, but it sounds > > like it. Is the finalization called at a defined moment? > Finalization is called at defined moments. > Every object is finalized before being destroyed (for example, by > leaving a subprogram_body containing an object_declaration, or by a > call to an instance of Unchecked_Deallocation). > Finalization also occurs as one step in an assignment operation: > For an assignment_statement, after the name and expression have been > evaluated, and any conversion (including constraint checking) has been > done, an anonymous object is created, and the value is assigned into > it; > that is, the assignment operation is applied. (Assignment includes > value adjustment.) The target of the assignment_statement is then > finalized. The value of the anonymous object is then assigned into the > target of the assignment_statement. Finally, the anonymous object is > finalized. Interesting. It sounds like the compiler generated "assignment operator" does exactly what good assignment operators do in C++. The classical idiom in C++ is to copy construct a temporary from the right hand side (the anonymous object which is created), then swap all of the fields with the target object, so that the anonymous object has the bit pattern of the original object, and vice versa. On leaving the assignment operator, the anonymous object goes out of scope, which causes its destructor to be called -- if everything is coded correctly, this has the effect of "finalizing" whatever the left hand side of the assignment held before. Because of the swap, C++ gets by with one finalization less:-). On the other hand, because this is a programmer implemented idiom, and the assignment operator is normally written by the programmer (with the default being nothing other than a member by member assignment), C++ requires programmers to distinguish between initialization and assignment -- in initialization, you are given raw memory as a target, and in assignment, a completely constructed object. If I understand you correctly, in Ada, the programmer is never concerned with assignment, as defined in C++: the compiler generated assignment operator generates code to use initialization and finalization. -- James Kanze GABI Software mailto:kanze@gabi-soft.fr Conseils en informatique orient�e objet/ Beratung in objektorientierter Datenverarbeitung 11 rue de Rambouillet, 78460 Chevreuse, France, T�l. : +33 (0)1 30 23 45 16 [ See http://www.gotw.ca/resources/clcm.htm for info about ] [ comp.lang.c++.moderated. First time posters: Do this! ]