64,685
社区成员
发帖
与我相关
我的任务
分享
#include<string>
#include<iostream>
#include<vector>
using namespace std;
class Screen
{
public:
friend class Window_mgr;
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 ht, pos wd) const; //显式内联
Screen& move(pos r, pos c);
void somemember() const;
inline Screen& set(char);
inline Screen& set(pos, pos, char);
Screen& display(std::ostream& out){ do_display(out); return *this; };
const Screen& display(std::ostream& out) const { do_display(out); return *this; };
private:
pos cursor = 0;
pos height = 0, width = 0;
std::string contents;
mutable string::size_type access_ctr; //在const对象内也可以被修改access_ctr
void do_display(std::ostream& out) const{ out << contents; }
};
class Window_mgr
{
public:
using ScreenIndex = std::vector<Screen>::size_type;
void clear(ScreenIndex);
private:
vector<Screen> screens = { Screen(24, 80, ' ') }; //问题出在这一行
};