class Window_mgr
{
public:
using ScreenIndex = vector<Screen>::size_type;
void clear(ScreenIndex);
private:
vector<Screen> screens{ Screen(24,80,' ') }; //一个Window_mgr包含一个标准尺寸的空白Screen
};
// 必须先声明Window_mgr 然后定义Screen 然后声明Window_mgr类的clear成员函数
class Screen
{
friend void Window_mgr::clear(ScreenIndex);
public:
using pos = string::size_type;
Screen() = default; //默认构造函数
Screen(pos h, pos w) :height(h), width(w), contents(h* w, ' ') {} //突然明白了这个初始化的方式。
Screen(pos h, pos w, char c) :height(h), width(w), contents(h* w, c){}
//cursor被类内初始化为0 如果类内不存在cursor的初始值,则必须显式地初始化cursor
public:
char get()const { return contents[cursor]; } //隐式内联
inline char get(pos h, pos w)const; //显示内联
Screen& move(pos h, pos w); //可以在之后被设为内联
Screen& set(pos, pos, char);
Screen& set(char);
Screen& display(ostream&os)
{
do_print(os); //this指针隐式地从指向非常量的指针转换为指向常量的指针
return *this; //this指向一个非
【c++primer】 Screen Window_mgr类的实现解析
最新推荐文章于 2024-07-15 18:35:16 发布