7.3.2. Functions That Return *this
Next we’ll add functions to set the character at the cursor or at a given location:
class Screen {public: Screen &set(char); Screen &set(pos, pos, char); // other members as before};inline Screen &Screen::set(char c){ contents[cursor] = c; // set the new value at the current cursor location return *this; // return this object as an lvalue}inline Screen &Screen::set(pos r, pos col, char ch){ contents[r*width + col] = ch; // set specified location to given value return *this; // return this object as an lvalue}
Like the move
operation, our set
members return a reference ...
Get C++ Primer, Fifth Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.