#pragma once
#include <iostream>
#include <string>
#include <vector>
using namespace std;
class Screen {
friend void Window_mgr::clear(vector< Screen>::size_type);
public:
typedef string::size_type pos;
Screen() = default;
Screen(pos ht, pos wd, char c) : cursor(0),
height(ht), width(wd) { }
char get()const
{
return contents[cursor];
}
inline char get(pos ht, pos wd)const;
Screen &move(pos r, pos c);
void some_memeber()const;
Screen &set(char);
Screen &set(pos, pos, char);
Screen &display(ostream &os)
{
do_display(os);
return *this;
};
const Screen &display(ostream &os)const
{
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::move(pos r, pos c)
{
pos row = r*width;
cursor = row + c;
return *this;
}
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;
}
#pragma once
#include <iostream>
#include <vector>
#include <string>
#include "Screen.h"
class Screen;
using namespace std;
class Window_mgr
{
public:
using ScreenIndex = vector< Screen>::size_type;
void clear(ScreenIndex);
private:
vector<Screen> screens{ Screen(20, 40, 'x') };
};
#include "Window_mgr.h"
class Screen;
void Window_mgr::clear(ScreenIndex i)
{
Screen &s = screens[i];
s.contents = string(s.height*s.width, ' ');
}
报错信息如下:
严重性 代码 说明 项目 文件 行
错误 C2248 “Screen::contents”: 无法访问 private 成员(在“Screen”类中声明) test0 c:\users\administrator\documents\visual studio 2015\projects\test0\test0\window_mgr.cpp 11
严重性 代码 说明 项目 文件 行
错误 C2248 “Screen::height”: 无法访问 private 成员(在“Screen”类中声明) test0 c:\users\administrator\documents\visual studio 2015\projects\test0\test0\window_mgr.cpp 11
严重性 代码 说明 项目 文件 行
错误 C2248 “Screen::width”: 无法访问 private 成员(在“Screen”类中声明) test0 c:\users\administrator\documents\visual studio 2015\projects\test0\test0\window_mgr.cpp 11
严重性 代码 说明 项目 文件 行
错误(活动) 后面有“::”的名称一定是类名或命名空间名 test0 c:\Users\Administrator\Documents\Visual Studio 2015\Projects\test0\test0\Screen.h 9
严重性 代码 说明 项目 文件 行
错误 C2027 使用了未定义类型“Window_mgr” test0 c:\users\administrator\documents\visual studio 2015\projects\test0\test0\screen.h 12