189. this Pointer

Question.2

An LCD class returns *this from each method:

class LCD {
public:
   LCD& clear() { /* ... */ return *this; }
   LCD& setCursor(int x, int y) { /* ... */ return *this; }
   LCD& print(const char* s) { /* ... */ return *this; }
};

LCD screen;
screen.clear().setCursor(0,1).print("Ready");

How does the chaining work?

Need Help? Refer to the Quick Guide below

Select Answer