We’re back to another function that has no real analogue in C++. The update-instance-for-different-class generic function is not to be called by the programmer, but it is still useful to know about it, as the programmer can specialize an :after or :before method to take special action.
In Lisp, it is possible to convert an instance to a new type with the change-class generic function. This was demonstrated in an earlier article, along with a specialized :before method for update-instance-for-different-class that allowed me to display the contents of the object prior to its being changed.
What are the cases when the programmer might want to specialize this generic function? Well, the default behaviour of update-instance-for-different-class is to copy slots with the same name from the old to the new instance and initialize new slots according to their initarg or initform forms, if any. Slots in the old class whose names do not appear in the new class have their values discarded. A :before method allows the programmer to examine those slots soon to disappear and take action based on their contents. An :after method, on the other hand, has access both to the original instance and to the post-copy, post-initialize slots in the new class, and can take further action to initialize or change slots based on those values.