.TH G_COPY 2 "11 April 1991" "Demeter" "Demeter Software" .SH NAME g_copy \- sends the generic copy message to an object. .SH SYNOPSIS virtual Universal* Universal:: .I g_copy () .SH DESCRIPTION .I g_copy performs a deep copy of the object to which the message is sent and returns the copy. This means that .I g_copy makes an instance of the class of the object. .I g_copy is then sent recursively to each part of the object to fill in the corresponding part in the newly made instance. The receiving object must be a tree object. That is, it cannot have any cycles or shared subobjects. .SH REDEFINITION Since .I g_copy is a virtual function, it can be redefined at any user class. This means that the user can change what .I g_copy returns as a copy of any object. As a technical consideration, making .I g_copy virtual allows to define it recursively and to give the termination condition as a redefinition at the terminal classes DemIdent, DemNumber, DemReal, DemString, and DemText. .SH RETURN VALUES .I g_copy returns an object of the class of the object to which the message was sent. However, the type returned by .I g_copy is .I Universal*, since .I g_copy does not know in advance to what class the message is going to be sent. Therefore, the value returned must be cast to the appropriate type before it can be assigned or used in any way. For example: Compound* iCompound = new Compound(); .br iCompound = (Compound*)iCompound->g_parse("demeter-input"); .br .br Compound* iCompound2 = (Compound*)iCompound->g_copy(); .br .br if( iCompound->g_equal( iCompound2 ) == 1 ) .br cout << \&"Copied and original are equal\en\&"; .br else .br cout << \&"Copied and original are NOT equal\en\&"; .SH SEE ALSO g_parse(2), g_equal(2), terminal(2), g_code(2), g_delete(2) .SH REFERENCES .I User Manual for The C++ Demeter System .br Walter L. Hursch .br Northeastern University, 1993 .I The Annotated C++ Reference Manual .br Margaret A. Ellis and Bjarne Stroustrup .br Addison-Wesley, 1990 .I C++ Primer .br Stanley B. Lippman .br Addison-Wesley, 1989