#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