I am facing a problem with the code below which is run on Visual Studio 2008. How do I write the function definition for operator + when you have a statement to be overloaded as follows?
class Distance
{
private:
int feet,inches;
};
main......
Distance Obj, Obj1(2, 2);
Obj = 3 + Obj1; // This line here
Obj1+3 is easy, but how does this one compiler know that it has to do overloading?
Suppose I have to add the value 3 to the data member feet of Obj1.
Generally an operator of that form would be declared as:
You’d probably also want to define the symmetric:
Also, I suggest you heed the advice of James McNellis–your job will be simplified if you just have one member representing lengths in a single unit.