In embedded firmware systems, hardware drivers are often accessed through a common interface so that different peripherals can be managed uniformly.
This relies on runtime polymorphism, where derived driver implementations override virtual functions defined in a base driver interface.
However, passing polymorphic objects by value causes object slicing, which removes the derived portion of the object and breaks runtime dispatch.
Your task is to correct the given program so that runtime polymorphism is preserved, and the correct derived driver behavior executes when processed through the base interface.
You must fix the object slicing issue without redesigning the driver class hierarchy.
Input / Program Flow
Driver selection rules:
0, use the SPI driver1, use the I2C driverProgram flow:
Output
If input is 0, output:
SPI driver runningIf input is 1, output:
I2C driver runningOutput Requirements
Constraints
new, delete)
Input
0
Expected Output
SPI driver running