#include<iostream>
#include<string>
using namespace std;
class Screen;
class Dog
{
public:
int foo(Screen & screen);
};
class Screen
{
public:
friend int calcArea(Screen &);//对一个函数进行友元
friend class Window_Mgr;//对整个类进行友元
//friend class Dog;
friend int Dog::foo(Screen & );//指定类当中的某一个函数为友元
typedef std::string::size_type index;
Screen(int ht=0, int wd=0):contents(ht*wd,' '),cursor(0),height(ht),width(wd){
}
int area()const
{
return height*width;
}
private:
std::string contents;
index cursor;
int height,width;
};
class Window_Mgr//窗口管理类 对Screen进行管理
{
public:
void relocate(int r, int c, Screen &s)
{
s.height += r;
s.width += c;
}
};
int Dog::foo(Screen & screen)
{
return screen.height * screen.width;
}
//这个函数不是类的成员函数
int calcArea(Screen & screen)
{
return screen.height*screen.width;
}
int main()
{
Screen a(60,100);
cout<<a.area()<<endl;
Window_Mgr wm;
wm.relocate(20,100,a);
cout<<"ok"<<endl;
cout<<calcArea(a)<<endl;
return 0;
}