#include <iostream>
using std::cout;
class distance {
private :
int feet;
int inches;
public :
void setfeet(int x) { feet = x; }
int getfeet(void) { return feet; }
void setinches(int y) { inches = y; }
int getinches(void) { return inches; }
distance add(distance temp) {
distance result(0, 0);
result.feet = feet + temp.feet;
result.inches = inches + temp.inches;
return result;
}
distance(int ft, int in) : feet(ft), inches(in) {}
};
int main(void)
{
distance a(5, 6);
distance b(3, 4);
distance sum(a.add(b));
cout << sum.getfeet() <<"\n";
cout << sum.getinches() << "\n";
return 0;
}
In this code sample, I can access private data members of result object which is created inside the method add and I can also access the private data member of object temp which is a parameter in the method add using the dot(.) operator how is that possible?