| OCR Text |
Show 111 an object has N slots each meaningful in one of N languages, N constructors must be called in turn. The naive approach to incremental construction is to invoke each constructor in turn on the same raw memory. However, this immediately leads to problems. If a constructor transforms raw memory into an object, then the second (and subsequent) constructor( s) must be coerced into operating on "preinitialized" memory. Furthermore, they must not be allowed to re-initialize the already initialized sections. Although a C++ constructor might be written to allow this behavior (using the placement syntax of an overloaded new operator), it is clear that this is not a common feature of OOPLs in general. If we recognize that what is restricted to one language is the interpretation and acquisition of the language dependent value, but usually not its representation, then another approach presents itself. An object with a slot dependent upon language X is first constructed in language X. The X specific constructor initializes those slots it can and sets the rest to zero. Then the value is naively accessed as an argument to the current language constructor. This approach involves constructing "partial" objects, then destroying them before construction is complete. It is unclear whether this is an acceptable compromise. It is possible to envision classes which require more self-consistency than this allows. For instance, a reference counted object may be partially constructed without incrementing the count. In this case the destructor must either be avoided entirely or must be able to recognize partial objects. Calling the foreign language constructor must be implemented with care since the object's copy constructor cannot be used to copy the "partial" object onto the stack. That would recursively invoke the constructor. Instead the copy constructor must be avoided and the copy operation performed "by hand." Note that this problem occurs for either the "preinitialized memory" approach or the "value copying, partial object" approach. In the first case, we actually pass a partial object |