I'm reading a book and doing an exercise where I just basically add some members, one of which is a const member function. It returns *this and I have it just like it has in the book, but it's giving me an error
Code:
class Screen
{
public:
typedef std::string::size_type index;
Screen(index h, index w, std::string c) :
height(h), width(w), contents(c){}
Screen &move(index, index);
Screen &set(char);
Screen &set(index, index, char);
const Screen &display(std::ostream &os) const //error
{ do_display(os); return *this; } //
Screen &display(std::ostream out)
{ do_display(out); return *this; }
private:
void do_display(std::ostream &out) {out << contents;}
std::string contents;
index cursor;
index height, width;
};
The error is as follows
[code]
Screen.h:21: error: passing `const Screen' as `this' argument of `void Screen::do_display(std::ostream&)' discards qualifiers
[code]