Including header in order
Hi.. I have two classes in two different order.. The classes are
Code:
#ifndef SCREEN_H_INCLUDED
#define SCREEN_H_INCLUDED
class Screen;
class Window_mgr;
class Screen{
friend void Window_mgr::clear(ScreenIndex);
friend void showscreen(const Screen&);
friend istream &read(istream&,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);
private:
mutable size_t access_ctr;
pos cursor=0;
pos height=0,width=0;
string contents;
};
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=width*r;
return contents[row+c];
}
void Screen::some_member() const
{
++access_ctr;
}
void showscreen(const Screen &in)
{
for(unsigned i=0;i<in.height*in.width;++i)
{
if(i&&i%in.width==0) cout<<endl;
cout<<in.contents[i];
}
cout<<endl;
}
istream &read(istream &is,Screen &in)
{
cout<<"Enter the height,width and character of the screen seperated by space "<<endl;
is>>in.height>>in.width;
char c=getwchar();
string s(in.height*in.width,c);
in.contents=s;
return is;
}
inline Screen &Screen::set(char c)
{
contents[cursor]=c;
return *this;
}
inline Screen &Screen::set(pos r,pos col,char c)
{
contents[r*width+col]=c;
return *this;
}
#endif // SCREEN_H_INCLUDED
and
Code:
#ifndef WINDOW_MGR_H_INCLUDED
#define WINDOW_MGR_H_INCLUDED
class Screen;
class Window_mgr;
struct Window_mgr{
public:
using ScreenIndex=std::vector<Screen>::size_type;
void clear(ScreenIndex);
private:
std::vector<Screen> screens{Screen(24,80,' ')};
};
void Window_mgr::clear(ScreenIndex i)
{
Screen &s=screens[i];
s.contents=string(s.width*s.height,' ');
}
#endif // WINDOW_MGR_H_INCLUDED
I want to make only clear function of Window_mgr as friend.. It is not compiling. Which order should I include.
may main file is
Code:
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#include "Screen.h"
#include "Window_mgr.h"
int main()
{
Screen sc;
read(cin,sc);
sc.set(1,3,'D');
sc.move(4,0).set('#');
showscreen(sc);
}