Hi, guys, trying to understand operator overloading, and i wrote some code just to define a "-" operator to do a simple subtraction. SO, i wrote a program that can perform a subtraction between two objects and put the result in the third object. now I Just cant show the result on the console.Can any one help? And also can anyone define the meaning of [b1.x], like I want to know am I assigning the value to the "b1"object or the x variable?
This is a very concept that I need to understand.Any help would be highly appreciated.
#include<iostream>
usingnamespace std;
struct Ok
{
int x;
int y;
};
Ok operator-(const Ok& a , const Ok& b)
{
Ok result;
result = (a - b);
return result;
}
int main()
{
Ok b1;
Ok b2;
Ok b3;
b1.x = 4;
b2.y = 3;
b3 = b1 - b2;
cout<<b3<<endl; //doesnt work
}