O'Reilly logo

C++ Primer, Fifth Edition by Barbara E. Moo, Josée Lajoie, Stanley B. Lippman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

7.3.2. Functions That Return *this

Image

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required