The class Distance is already defined with:
- A private data member
meters - A constructor that initializes
meters - A method
getMeters() that returns the stored value
Your task is to overload the + operator so that two Distance objects can be added together.
The result must be a new Distance object whose meters value is the sum of the two operands.
This problem is designed for embedded C++ practice, where explicit data sizes and predictable behavior are required.
Example
Input:
5 7
Output:
Total=12
Constraints
meters is a signed 32-bit integer (int32_t)- Input values are guaranteed to be in the range −1,000,000 to +1,000,000
- The sum of two valid inputs will not overflow a 32-bit signed integer
- Negative values are allowed
- No dynamic memory allocation is permitted
- Operator overloading must not modify existing objects