⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 friend2.cpp

📁 Thinking in C++ 2nd edition source code which are all the cores of the book Thinking in C++ second e
💻 CPP
字号:
//: C03:Friend2.cpp
// From Thinking in C++, 2nd Edition
// at http://www.BruceEckel.com
// (c) Bruce Eckel 1999
// Copyright notice in Copyright.txt
// Making an entire class a friend
class Watch {
  int time;  // A measure of time
  int alarm;  // When the alarm goes off
  int date;   // Other things a Watch should know
public:
  // Constructor sets starting state:
  Watch() { time = alarm = date = 0; }
  void tick() { time++; } // Very simple transition
  // Allow all members of MicrowaveOven access to private
  // Elements of Watch:
  friend class MicrowaveOven;
};

class MicrowaveOven {
  int time;
  int start_time;
  int stop_time;
  int intensity;
public:
  MicrowaveOven() {
    time = 0;
    start_time = stop_time = 0;
    intensity = 0;
  }
  void tick() { time++; }
  void synchronize(Watch & WA) {
    time = WA.time = 15;  // Set both to a common state
  }
};

int main() {
  Watch que_hora;
  MicrowaveOven nuke;
  que_hora.tick();
  que_hora.tick();
  nuke.tick();
  nuke.synchronize(que_hora);
} ///:~

⌨️ 快捷键说明

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