c++ primer类(1)
#include<iostream>
#include<vector>
using namespace std;
class Screen {
public:
typedef string::size_type pos;
Screen() = default;
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 some_member() const;
Screen& set(char);
Screen& set(pos,pos,char);
Screen& display(ostream &os){do_display(os);return *this;}
private:
pos cursor = 0;
pos height = 0,width = 0;
string contents;
mutable size_t access_ctr;
void do_display(ostream &os) const{os << contents;}
};
inline Screen& Screen::set(char c){
contents[cursor] = c;
return *this;
}
inline Screen& Screen::set(pos r,pos col,char ch){
contents[r*width + col] = ch;
return *this;
}
inline
Screen &Screen::move(pos r,pos c){
pos row = r * width;
cursor = row + c;
return *this;
}
char Screen::get(pos r,pos c) const{
pos row = r * width;
return contents[row + c];
}
void Screen::some_member() const{
++(this->access_ctr);
};
class Window_mgr{
private:
vector<Screen> screens{Screen(24,80,' ')};
};
class Screen1{
private:
string contents;
int height = 0;
int width = 0;
public:
Screen1() = default;
Screen1(int ht,int wd):height(ht),width(wd),contents(" ") { };
Screen1(int ht,int wd,char c):height(ht),width(wd),contents(ht*wd,c) { };
Screen1& set(char);
};
int main(int argc, char const *argv[])
{
Screen myScreen(5,5,'x');
myScreen.move(4,0).set('#').display(cout);
cout << "\n";
myScreen.display(cout);
cout << "\n";
return 0;
}
class Link_Screen{
friend class
Screen window;
Link_Screen *next;
Link_Screen *prev;
Link_Screen &p;
};
class X{
Y *ptr;
};
class Y{
X x_in_y;
};