7.3.4 friend class

#ifndef MYSCREEN_H
#define MYHSCREEN_H


#include"string.h"
//#include "Window_mgr.h"
#include<vector>

class Window_mgr;
class Screen
{
public:
	typedef string::size_type pos;
	Screen()=default;
//	Screen(pos ht,pos wi):height(ht),width(wi){};
	Screen(pos ht,pos wi,char c):
			height(ht),width(wi),contents(ht*wi,c){}
			//==string(10,'c')
	char get()const{return contents[cursor];}
	inline char get(pos ht,pos wi)const;
	inline Screen	move(pos ht,pos wi);
	inline Screen set(char c);
	inline ostream& display(ostream& os);
	pos Screen::size()const;

	friend class Window_mgr;

private:
//friend Window_mgr;
	pos height,width,cursor;//屏幕和光标的位置
	string contents;//string 有下标,当前位置
	
};
Screen::pos 
Screen::size()const
{
	return height*width;
};
inline Screen Screen::move(pos ht,pos wi)
{
	pos row=ht*width;
	cursor=row+wi;
	return *this;
}
inline Screen Screen::set(char c)
{
	contents[cursor]=c;	
	return *this;
}
inline ostream& Screen::display(ostream& os)
{
	return os<<contents[cursor];
}
char Screen::get(pos ht,pos wi)const
{
	pos row=ht*width;
	return contents[row+wi];
}

class Window_mgr
{
	Window_mgr() = default;
//	vector<Screen> screens{ Screen(24, 80, ' ') };
public:
	typedef vector<Screen>::size_type ScreenIndex;
	void clear(ScreenIndex);
};

  void Window_mgr::clear(ScreenIndex x)
{
	Screen& s = screens[x];
	s.contents = string{' ',s.height*s.width}; //s.height*s.width
}

#endif

报错,don't know why




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值