In embedded firmware, drivers are commonly layered to separate responsibilities and ensure correct hardware bring-up.
A typical structure looks like:
In C++, multilevel inheritance guarantees a strict constructor execution order, which is critical in such designs.
Your task is to implement and verify constructor execution order in a three-level inheritance hierarchy that mimics a real firmware driver stack.
Scenario
You must implement the following class hierarchy:
CoreDriver
↓
CommDriver
↓
SpiDriver
Each class represents a firmware layer and performs initialization in its constructor.
Requirements
Step 1: CoreDriver
CoreDriverProvide a constructor that prints exactly:
Core driver initialized
Step 2: CommDriver
CommDriverCoreDriverProvide a constructor that prints exactly:
Comm driver initialized
Step 3: SpiDriver
SpiDriverCommDriverspeedPrints exactly:
SPI driver initialized
speed value internallyProvide a member function that prints:
SPI speed <speed>
Input
One integer value:
speed
Program Flow (Mandatory Order)
speed from standard inputSpiDriver object using speedCoreDriverCommDriverSpiDriver
Example Input
8
Example Output
Core driver initialized
Comm driver initialized
SPI driver initialized
SPI speed 8
Constraints (Strict)
new, malloc)
Input
8
Expected Output
Core driver initialized Comm driver initialized SPI driver initialized SPI speed 8