You are implementing a sensor packet class that owns dynamically allocated memory.
The class manages a fixed-size buffer of exactly 8 bytes stored on the heap.
Your goal is to correctly implement resource ownership using:
This problem is designed to verify correct handling of dynamic memory in Embedded C++, where improper copy behavior can cause double-free, memory corruption, or silent data errors.
Class Design:
Private:
uint8_t* data;Public operations:
uint8_t arr[8]SensorData(const SensorData& other)~SensorData()void setIndex3()data[3] = 99void print() constProgram Flow:
a using those valuesa into object b using copy initializationb by calling setIndex3()a, then print bCorrect Behavior:
a must retain the original datab must show the modified value at index 3
Example Input:
1 2 3 4 5 6 7 8 Example Output:
1 2 3 4 5 6 7 8
1 2 3 99 5 6 7 8
Constraints:
new uint8_t[8]delete[]data pointer
Input
1 2 3 4 5 6 7 8
Expected Output
1 2 3 4 5 6 7 8 1 2 3 99 5 6 7 8