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

📄 keywords_details.html

📁 ssd5 数据结构的课件
💻 HTML
📖 第 1 页 / 共 3 页
字号:
    <h2><a name="switch">switch</a></h2>    <i>Syntax:</i>     <table bgcolor="#ccccff">      <tr>        <td><pre>  switch( expression ) {    case A:      statement list;      break;    case B:      statement list;      break;    ...    case N:      statement list;      break;    default:      statement list;      break;  }</pre>        </td>      </tr>    </table>    <p>The switch statement allows you to test an expression for many values, and is commonly used as a    replacement for multiple <a href="#if">if()</a>...else if()...else if()... statements. <a href=    "#break">break</a> statements are required between each <a href="#case">case</a> statement, otherwise    execution will "fall-through" to the next case statement. The <a href="#default">default</a> case is    optional. If provided, it will match any case not explicitly covered by the preceding cases in the switch    statement. For example:</p><pre>    char keystroke = getch();    switch( keystroke ) {      case 'a':      case 'b':      case 'c':      case 'd':        KeyABCDPressed();        break;      case 'e':        KeyEPressed();        break;      default:        UnknownKeyPressed();        break;    }</pre>    <i>Related topics:</i><br>    <strong><a href="#break">break</a>, <a href="#case">case</a>, <a href="#default">default</a>, <a href=    "#if">if</a></strong>     <hr>    <h2><a name="template">template</a></h2>    <i>Syntax:</i>     <table bgcolor="#ccccff">      <tr>        <td><pre>  template &lt;class data-type&gt; return-type name( parameter-list ) {    statement-list;  }</pre>        </td>      </tr>    </table>    <p>Templates are used to create generic functions and can operate on data without knowing the nature of    that data. They accomplish this by using a placeholder <i>data-type</i> for which many other data types    can be substituted. For example:</p><pre>    template&lt;class X&gt; void genericSwap( X &amp;a, X &amp;b ) {      X tmp;        tmp = a;      a = b;      b = tmp;    }         int main(void) {      ...      int num1 = 5;      int num2 = 21;      cout &lt;&lt; "Before, num1 is " &lt;&lt; num1 &lt;&lt; " and num2 is " &lt;&lt; num2 &lt;&lt; endl;      genericSwap( num1, num2 );      cout &lt;&lt; "After, num1 is " &lt;&lt; num1 &lt;&lt; " and num2 is " &lt;&lt; num2 &lt;&lt; endl;      char c1 = 'a';      char c2 = 'z';      cout &lt;&lt; "Before, c1 is " &lt;&lt; c1 &lt;&lt; " and c2 is " &lt;&lt; c2 &lt;&lt; endl;      genericSwap( c1, c2 );      cout &lt;&lt; "After, c1 is " &lt;&lt; c1 &lt;&lt; " and c2 is " &lt;&lt; c2 &lt;&lt; endl;      ...      return( 0 );    }</pre>    <hr>    <h2><a name="this">this</a></h2>    <p>The this keyword is a pointer to the current object. All member functions of a <a href=    "#class">class</a> have a this pointer.</p>    <i>Related topics:</i><br>    <strong><a href="#class">class</a></strong>     <hr>    <h2><a name="throw">throw</a></h2>    <i>Syntax:</i>     <table bgcolor="#ccccff">      <tr>        <td><pre>  try {    statement list;  }  catch( typeA arg ) {    statement list;  }  catch( typeB arg ) {    statement list;  }  ...  catch( typeN arg ) {    statement list;  }</pre>        </td>      </tr>    </table>    <p>The throw statement is part of the C++ mechanism for exception handling. Together with the <a href=    "#try">try</a> and <a href="#catch">catch</a> statements, the C++ exception handling system gives    programmers an elegant mechanism for error recovery. You will generally use a <a href="#try">try</a>    block to execute potentially error-prone code. Somewhere in this code, a <strong>throw</strong> statement    can be executed, which will cause execution to jump out of the try block and into one of the <a href=    "#catch">catch</a> blocks. For example:</p><pre>    try {      cout &lt;&lt; "Before throwing exception" &lt;&lt; endl;      throw 42;      cout &lt;&lt; "Shouldn't ever see this" &lt;&lt; endl;    }      catch( int error ) {      cout &lt;&lt; "Error: caught exception " &lt;&lt; error &lt;&lt; endl;    }</pre>    <i>Related topics:</i><br>    <strong><a href="#catch">catch</a>, <a href="#try">try</a></strong>     <hr>    <h2><a name="true">true</a></h2>    <p>The Boolean value of "true".</p>    <i>Related topics:</i><br>    <strong><a href="#bool">bool</a>, <a href="#false">false</a></strong>     <hr>    <h2><a name="try">try</a></h2>    <p>The try statement attempts to execute exception-generating code. See the <a href="#throw">throw</a>    statement for more details.</p>    <i>Related topics:</i><br>    <strong><a href="#catch">catch</a>, <a href="#throw">throw</a></strong>     <hr>    <h2><a name="typedef">typedef</a></h2>    <i>Syntax:</i>     <table bgcolor="#ccccff">      <tr>        <td><pre>  typedef existing-type new-type;</pre>        </td>      </tr>    </table>    <p>The typedef keyword allows you to create a new type from an existing type.</p>    <hr>    <h2><a name="typeid">typeid</a></h2>    <i>Syntax:</i>     <table bgcolor="#ccccff">      <tr>        <td><pre>  typeid( object );</pre>        </td>      </tr>    </table>    <p>The typeid operator returns a reference to a <strong>type_info</strong> object that describes    <i>object</i>.</p>    <hr>    <h2><a name="typename">typename</a></h2>    <p>The typename keyword can be used to describe an undefined type or in place of the class keyword in a    <a href="#template">template</a> declaration.</p>    <hr>    <h2><a name="union">union</a></h2>    <i>Syntax:</i>     <table bgcolor="#ccccff">      <tr>        <td><pre>  union union-name {    public-members-list;        private:      private-members-list;  } object-list;</pre>        </td>      </tr>    </table>    <p>Unions are like <a href="#class">classes</a>, except that all members of a union share the same memory    location and are by default public rather than private. For example:</p><pre>    union Data {      int i;      char c;    };</pre>    <i>Related topics:</i><br>    <strong><a href="#class">class</a>, <a href="#struct">struct</a></strong>     <hr>    <h2><a name="unsigned">unsigned</a></h2>    <p>The unsigned keyword is a data type modifier that is usually used to declare unsigned int variables.    See the <a href="data_types.html">data types</a> page.</p>    <i>Related topics:</i><br>    <strong><a href="#signed">signed</a></strong>     <hr>    <h2><a name="using">using</a></h2>    <p>The using keyword is used to import a <a href="#namespace">namespace</a> into the current scope.</p>    <i>Related topics:</i><br>    <strong><a href="#namespace">namespace</a></strong>     <hr>    <h2><a name="virtual">virtual</a></h2>    <i>Syntax:</i>     <table bgcolor="#ccccff">      <tr>        <td><pre>  virtual return-type name( parameter-list );  virtual return-type name( parameter-list ) = 0;</pre>        </td>      </tr>    </table>    <p>    The virtual keyword can be used to create virtual functions, which    can be overridden by derived classes.      <ul>    <li>A virtual function indicates that a function can be overridden    in a subclass, and that the overridden function will actually be    used.</li>    <li>When a base object pointer points to a derived object that    contains a virual function, the decision about which version of    that function to call is based on the type of object pointed to by    the pointer, and this process happens at runtime.</li>    <li>A base object can point to different derived    objects and have different versions of the virual function run.</li>    </ul>    </p>    <p>    If the function is specified as a pure virtual function (denoted by    the = 0), it <i>must</i> be overridden by a derived class.    </p>    <hr>    <h2><a name="volatile">volatile</a></h2>    <p>The volatile keyword is an implementation-dependent modifier, used when declaring variables, which    prevents the compiler from optimizing those variables. Volatile should be used with variables whose value    can change in unexpected ways (i.e. through an interrupt), which could conflict with optimizations that    the compiler might perform.</p>    <hr>    <h2><a name="void">void</a></h2>    <p>The void keyword is used to denote functions that return no value, or generic variables which can    point to any type of data. Void can also be used to declare an empty parameter list. Also see the <a    href="data_types.html">data types</a> page.</p>    <hr>    <h2><a name="wchar_t">wchar_t</a></h2>    <p>The keyword wchar_t is used to declare wide character variables. Also see the <a href=    "data_types.html">data types</a> page.</p>    <hr>    <h2><a name="while">while</a></h2>    <i>Syntax:</i>     <table bgcolor="#ccccff">      <tr>        <td><pre>  while( condition ) {    statement-list;  }</pre>        </td>      </tr>    </table>    <p>The while keyword is used as a looping construct that will evaluate the <i>statement-list</i> as long    as <i>condition</i> is true. Note that if the <i>condition</i> starts off as <a href="#false">false</a>,    the <i>statement-list</i> will never be executed. (You can use a <a href="#do">do</a> loop to guarantee    that the statement-list will be executed at least once.) For example:</p><pre>    bool done = false;    while( !done ) {      ProcessData();      if( StopLooping() ) {        done = true;      }    }</pre>    <i>Related topics:</i><br>    <strong><a href="#do">do</a>, <a href="#for">for</a></strong>  </body></html>

⌨️ 快捷键说明

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