In embedded systems, a driver often owns multiple internal resources whose lifetimes must be fully controlled and deterministic.
These resources are typically created when the driver is initialized and destroyed automatically when the driver shuts down.
In this task, you will model a driver that owns multiple internal resources using composition, ensuring correct construction and destruction order without dynamic allocation.
The driver owns:
Both resources must:
main()Do This:
Buffer class that stores one integerRegisterBlock class that stores one integerDriver class that owns both objects as direct members⚠️ Important C++ Rule (Required for Correct Output):
Class member objects are constructed in the order they are declared in the class, and destroyed in the reverse order, regardless of constructor body code.
Your solution must rely on this rule to match the required output exactly.
Program Flow:
Driver objectInput:
Two integers separated by whitespaceOutput (Exact Order Required):
Buffer created
RegisterBlock created
Driver initialized
Buffer value: <value1>
Register value: <value2>
Driver destroyed
RegisterBlock destroyed
Buffer destroyed
Constraints:
Buffer and RegisterBlock must not be created in main()
Input
10 20
Expected Output
Buffer created RegisterBlock created Driver initialized Buffer value: 10 Register value: 20 Driver destroyed RegisterBlock destroyed Buffer destroyed