【c++primer】 Screen Window_mgr类的实现解析

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指向一个非
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值