Hardware interview practice
Polymorphic deep copying
A mailbox stores base-class transaction handles, but derived transactions contain extra fields and nested class handles. Which copying design best preserves type and independence?
Starting point
Question code
mailbox #(base_txn) inbox;Choose one
Answer choices
- A. Assign the received base handle to a second base handle
- B. Use new received_object once in base code and rely on the built-in shallow copy
- C. Declare a virtual clone method and override it in every derived class to allocate its dynamic type and deep-copy owned nested objects
- D. Cast every received object to the first known derived type and reuse the same nested handles
