7.23
#ifndef SCREEN_H
#define SCREEN_H
class Screen {
public:
using pos = std::string::size_type;
Screen() = default;
Screen(pos ht, pos wd): height(ht), width(wd), contents(ht * wd, ' ') { }
Screen(pos ht, pos wd, char c): height(ht), width(wd), contents(ht * wd, c) { }
char get() const { return contents[cursor]; }
inline char get(pos r, pos c) const;
Screen &move(pos r, pos c);
private:
pos cursor = 0;
pos height = 0, width = 0;
std::string contents;
};
char Screen::get(pos r, pos c) const
{
return contents[r * width + c];
}
inline Screen &move(pos r, pos c)
{
cursor = r * width + c;
return *this;
}
#endif
7.24 见7.23代码
7.25 可以使用默认版本,其数据成员cursor,height和width都是内置类型,contents是string类型,定义了拷贝和赋值运算符,默认版本能够正确处理。
7.26
class Sales_data {
public:
/*