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

📄 mailbox.h.html

📁 《Big C++ 》Third Edition电子书和代码全集-Part1
💻 HTML
字号:
<html>

<head>
	<title>mailbox.h</title>
</head>

<body>
<pre>  1  #ifndef MAILBOX_H
  2  #define MAILBOX_H
  3  
  4  using namespace std;
  5  
  6  #include &lt;string&gt;
  7  #include &lt;queue&gt;
  8  
  9  class Message;
 10  
 <font color="#0000cc">11  /**
 12     A mailbox contains messages that can be listed, kept, or discarded
 13  */</font>
 14  class Mailbox
 15  {
 16  public:
 <font color="#0000cc">17     /**
 18        Create a mailbox object
 19        @param a_passcode passcode number
 20        @param a_greeting greeting string
 21     */</font>
 22     Mailbox(string a_passcode, string a_greeting);
 23  
 2<font color="#0000cc">4     /**
 25        Check if the passcode is correct
 26        @param a_passcode a passcode to check
 27     */</font>
 28     bool check_passcode(string a_passcode) const; 
 29  
 3<font color="#0000cc">0     /**
 31        Add a message to the mailbox
 32        @param a_message the message to be added
 33     */</font>
 34     void add_message(Message* a_message);
 35  
 <font color="#0000cc">36     /**
 37        Get the current message
 38        @return the current message
 39     */</font>
 40     Message* get_current_message() const;
 41  
 <font color="#0000cc">42     /**
 43        Remove the current message from the mailbox
 44     */</font>
 45     void remove_current_message();
 46  
 <font color="#0000cc">47     /**
 48        Save the current message
 49     */</font>
 50     void save_current_message();
 51  
 <font color="#0000cc">52     /**
 53        Change the mailbox's greeting
 54        @param new_greeting the new greeting string
 55     */</font>
 56     void set_greeting(string new_greeting);
 57  
 <font color="#0000cc">58     /**
 59        Change mailbox's passcode
 60        @param new_passcode the new passcode
 61     */</font>
 62     void set_passcode(string new_passcode);
 63  
 <font color="#0000cc">64     /**
 65        Get the mailbox's greeting
 66        @return the greeting
 67     */</font>
 68     string get_greeting() const;
 69  private:
 70     queue&lt;Message*&gt; new_messages;
 71     queue&lt;Message*&gt; kept_messages;
 72     string greeting;
 73     string passcode;
 74  };
 75  
 76  inline Mailbox::Mailbox(string a_passcode, string a_greeting)
 77     : passcode(a_passcode), greeting(a_greeting)
 78  {
 79  }
 80  
 81  inline bool Mailbox::check_passcode(string a_passcode) const
 82  {
 83     return passcode == a_passcode;
 84  }
 85  
 86  inline void Mailbox::add_message(Message* a_message)
 87  {
 88     new_messages.push(a_message);
 89  }
 90  
 91  inline void Mailbox::set_greeting(string new_greeting)
 92  {
 93     greeting = new_greeting;
 94  }
 95  
 96  inline void Mailbox::set_passcode(string new_passcode)
 97  {
 98     passcode = new_passcode;
 99  }
100  
101  inline string Mailbox::get_greeting() const
102  {
103     return greeting;
104  }
105  
106  #endif</pre>
</body>
</html>

⌨️ 快捷键说明

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