#include <iostream>
using namespace std;
class Height
{
public:
int feet, inch;
Height()
{
feet = 0;
inch = 0;
}
Height(int f, int i)
{
feet = f;
inch = i;
}
// Overloading (+) operator to perform addition of
// two distance object using binary operator
Height operator+(Height& d2) // Call by reference
here whats the parameter to the operator overloading function? is h3 object being sent as a parameter?
{
// Create an object to return
Height h3;
is it possible to create a new object within a operator overloading function?
// Perform addition of feet and inches
h3.feet = feet + d2.feet;
h3.inch = inch + d2.inch;
// Return the resulting object
return h3;
}
};
int main()
{
Height h1(3, 7);
does creating a first object automatically associate it to the first member constructer of the height class ?
Height h2(6, 1);
does creating a second object automatically associate it to the second member constructer of the height class ?
Height h3;
//Use overloaded operator
h3 = h1 + h2;
cout << "Sum of Feet & Inches: " << h3.feet << "'" << h3.inch << endl;
return 0;
}