Hi all,
i have difficulty understanding the following :
i have two classes : Point and Rectangle.
Code:
class Point // holds x,y coordinates
{
public:
void SetX(int x) { itsX = x; }
void SetY(int y) { itsY = y; }
int GetX()const { return itsX;}
int GetY()const { return itsY;}
private:
int itsX;
int itsY;
};
class Rectangle
{
public:
Rectangle (int top, int left, int bottom, int right);
~Rectangle () {}
Point GetUpperLeft() const { return itsUpperLeft; }
Point GetLowerLeft() const { return itsLowerLeft; }
Point GetUpperRight() const { return itsUpperRight; }
Point GetLowerRight() const { return itsLowerRight; }
void SetUpperLeft(Point Location) {itsUpperLeft = Location;}
void SetLowerLeft(Point Location) {itsLowerLeft = Location;}
void SetUpperRight(Point Location) {itsUpperRight = Location;}
void SetLowerRight(Point Location) {itsLowerRight = Location;}
private:
Point itsUpperLeft;
Point itsUpperRight;
Point itsLowerLeft;
Point itsLowerRight;
};
int main()
{
//initialize a local Rectangle variable
Rectangle MyRectangle (100, 20, 50, 80 );
std::cout << MyRectangle.GetUpperLeft().GetX();
my question is about this :
MyRectangle.GetUpperLeft().GetX()
i know that an object of Point can access a public method of Point.
But here i have a function (method of Rectangle class) from type Point that return a Point object. that's fine...why is this method able to call a method from the class Point ?
so a public method of the class X cannot only be accessed by an X object but also from a function of type X that can return an X object?