头文件Header.h:
#ifndef FUNC
#define FUNC
#include<string>
#include<vector>
using namespace std;
class Screen;
class Window_mgr
{
public:
friend class Screen;
typedef vector<Screen>::size_type ScreenIndex;
Window_mgr() = default;
ScreenIndex addScreen(const Screen&);
void clear(ScreenIndex);
private:
vector<Screen> screens{Screen(24,80,' ')};
};
class Screen
{
friend void Window_mgr::clear(ScreenIndex);
public:
typedef string::size_type pos;
Screen() = default;
Screen(pos ht, pos wd) :height(ht), width(wd){ contents = string(ht*wd, ' '); }
Screen(pos ht, pos wd, char c) :height(ht), width(wd), contents(ht*wd, c){}
char get()const { return contents[cursor]; cout << cursor << height << width; }
inline char get(pos ht, pos wd)const;
Screen &move(pos r, pos c){ cursor = r*width + c; return *this; }
Screen &set(char c){ contents[cursor] = c; return *this; }
inline Screen& display(ostream &);
private:
pos cursor = 0;
pos height = 0, width = 0;
string contents;
};
inline
Screen& Screen::display(ostream &co)
{
co << contents;
return *this;
}
Window_mgr::ScreenIndex
Window_mgr::addScreen(const Screen&s)
{
screens.push_back(s);
return screens.size()-1;
}
void Window_mgr::clear(ScreenIndex i)
{
Screen &s = screens[i];
s.contents = string(s.height*s.width, ' ');
}
#endif
源文件source.cpp:
#include<iostream>
#include"Header.h"
int main()
{
Window_mgr ms;
Screen myScreen(5, 5, 'X');
myScreen.move(4, 0).set('#').display(cout);
cout << "\n";
myScreen.display(cout);
cout << "\n";
return 0;
}
VS2013编译器提示 :
Error 1 error C2514: 'Screen' : class has no constructors c:\users\orgrand.w\documents\visual studio 2013\projects\demo\header.h 16 1 Demo
Error 2 error C1903: unable to recover from previous error(s); stopping compilation c:\users\orgrand.w\documents\visual studio 2013\projects\demo\header.h 16 1 Demo
光标指向这条语句: vector screens{Screen(24,80,' ')};
怎么修改才能实现这个初始化呢?