From 1343c5f4eba702614ed4a3d53874a6909ca16aed Mon Sep 17 00:00:00 2001 From: Technical Vandar <73782935+Technical-Vandar-885@users.noreply.github.com> Date: Fri, 1 Oct 2021 20:11:53 +0545 Subject: [PATCH] Create Binary_Operator_Overloading.cpp --- cpp/Binary_Operator_Overloading.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 cpp/Binary_Operator_Overloading.cpp diff --git a/cpp/Binary_Operator_Overloading.cpp b/cpp/Binary_Operator_Overloading.cpp new file mode 100644 index 000000000..d07a59e79 --- /dev/null +++ b/cpp/Binary_Operator_Overloading.cpp @@ -0,0 +1,28 @@ +#include +using namespace std; +class Distance { +public: + int feet, inch; + Distance() { + feet = 0; + inch = 0; + } + Distance(int f, int i){ + feet = f; + inch = i; + } + Distance operator+(Distance d2) { + Distance d3; + d3.feet = feet + d2.feet; + d3.inch = inch + d2.inch; + return d3; + } +}; +int main() { + Distance d1(8, 9); + Distance d2(10, 2); + Distance d3; + d3 = d1 + d2; + cout << "\nTotal Feet & Inches: " << d3.feet << "'" << d3.inch; + return 0; +}