I am sorry Athar.
In This Code :
#include <iostream>
#include <conio.h>
using namespace std;
class loc
{
private:
int longitude;
int latitude;
public:
loc() {} //needed to construct temporaries
loc(int lg, int lt)
{
longitude = lg;
latitude = lt;
}
loc operator+(loc op2);
loc operator-(loc op2);
loc operator=(loc op2);
loc operator++();
};
//******************
//overload + for loc
loc loc::operator+(loc op2)
{
loc temp;
temp.longitude = op2.longitude + longitude;
temp.latitude = op2.latitude + latitude;
return temp;
}
//********** overload - for loc ***********
loc loc::operator-(loc op2)
{
loc temp;
//notice order of operand
temp.longitude = longitude - op2.longitude;
temp.latitude = latitude - op2.latitude ;
return temp;
}
// overload assign for loc
loc loc::operator=(loc op2)
{
longitude = op2.longitude;
latitude = op2.latitude ;
return *this; // return object that generated call
}
//******* overload prefix ++ for loc
loc loc::operator++()
{
longitude ++;
latitude ++ ;
return *this; //return object that generated call
}
//**********************
int main()
{
Well, since you're passing op2 by value in operator=, the object is copied by invoking the copy constructor.
That will be slower than passing by reference for large and complex objects, but will usually have the same results if the copy contructor is properly implemented.