example5.cpp

来自「Advanced Internet Programming Lecture 2 」· C++ 代码 · 共 62 行

CPP
62
字号
#include <iostream>using namespace std;const int IDLE = 0;const int INUSE = 1;class C2;  // forward declarationclass C1 {  int status;  // IDLE if off, INUSE if on screen  // ...public:  void set_status(int state);  int idle(C2 b);  // now a member of C1};class C2 {  int status;  // IDLE if off, INUSE if on screen  // ...public:  void set_status(int state);  friend int C1::idle(C2 b);};void C1::set_status(int state){  status = state;}void C2::set_status(int state){  status = state;}// idle() is member of C1, but friend of C2int C1::idle(C2 b){  if(status || b.status) return 0;  else return 1;}int main(){  C1 x;  C2 y;  x.set_status(IDLE);  y.set_status(IDLE);  if(x.idle(y)) cout << "Screen can be used.\n";  else cout << "In use.\n";  x.set_status(INUSE);  if(x.idle(y)) cout << "Screen can be used.\n";  else cout << "In use.\n";  return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?