Hi
In this code , compiler first calculate ob1=ob2 or ob2=ob3 ( in that line that has written ob1=ob2=ob3 ) ?
#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;
}
As you should be able to see, operator= is evaluated from right to left.
That's a good thing too, otherwise
ob1 = ob2 = ob3; would have the same effect as ob1 = ob2;
It's not a good idea to return a copy in operator=, by the way. For such a small object it doesn't matter, but generally, you should return a const reference.