Write a program to add two distance object using operator member function.
#include <iostream>
struct dest {
double value;
};
struct dest operator+(const struct dest &a, const struct dest &b) {
return (struct dest) { a.value + b.value };
}
int main() {
struct dest a = { 4 };
struct dest b = { 23 };
struct dest c = a + b;
std::cout << c.value << std::endl;
return 0;
}
Comments
Leave a comment