#include <iostream>
#include <cstdint>

using namespace std;

class Distance {
private:
    int32_t meters;

public:
    Distance(int32_t m) : meters(m) {}

    // Define operator+ to add two Distance objects
    Distance operator +(const Distance& right) const {
        return Distance(meters + right.meters);
    }

    int32_t getMeters() const {
        return meters;
    }
};

int main() {
    int32_t a, b;
    cin >> a >> b;

    Distance d1(a);
    Distance d2(b);

    Distance total = d1 + d2;
    cout << "Total=" << total.getMeters();

    return 0;
}

Creates a new obj while adding 

 

 

 

 

Upvote
Downvote
Loading...

Input

5 7

Expected Output

Total=12