kindly explain

# include <iostream.h>
# include <conio.h>
class distance
{
int feet,inches;
public :
void distance_assign(int f, int i)
{
feet = f;
inches = i;
}
void display()
{
cout << “\nFeet : “ << feet
<< “\tInches : “ << inches;
}
distance operator+(distance d2)
{
distance d3;
d3.feet = feet + d2.feet;
d3.inches = (inches + d2.inches) % 12;
d3.feet += (inches + d2.inches)/12;
return d3;
}
};
void main()
{
clrscr();
distance dist_1,dist_2;
dist_1.distance_assign(12,11)
dist_2.distance_assign(24,1);
distance dist_3 = dist_1 + dist_2;
dist_1.display();
dist_2.display();
dist_3.display();
getch();
}

Questions.
1. What types of operands are used for the overloaded operator?
2. Write out the statement that invokes the overloaded member
function.
You already have a duplicate post
http://www.cplusplus.com/forum/beginner/208359/

This tells you all about the overload operators
http://en.cppreference.com/w/cpp/language/operators
Dear Hengry
Already I posted. But no one not reply. So Again I post this question. Kindly tell the two questions only.
What is an operand? Why are overloaded operators needed? If you can answer those two question you can figure out your two questions.

Please read this link, this will practically tell you the answer to your question.
https://www.tutorialspoint.com/cplusplus/cpp_overloading.htm

I wouldn't mind helping you if I am able to help, but you practically copy+pasted you code from your assignment. You didn't even use code tags even when someone replied to your previous post to use code tags.

1. What types of operands are used for the overloaded operator?

Read the function and you basically have your answer.
 
distance operator+(distance d2)



2. Write out the statement that invokes the overloaded member
function.
 
distance dist_3 = dist_1 + dist_2;
Hi integralfx

What types of operands are used for the overloaded operator?
distance is correct or not ?

What types of operands are used for the overloaded operator?
distance is correct or not ?

Yes, but I would prefer to answer the question more formally like

The overloaded addition operator takes objects of type distance as operands.
Hi integralfx

Thanks for your valuable help...
Topic archived. No new replies allowed.