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

📄 all.html

📁 从www.CppReference.com打包的C++参考手册
💻 HTML
📖 第 1 页 / 共 4 页
字号:
    <pre class="example-code">   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; &quot;Before, num1 is &quot; &lt;&lt; num1 &lt;&lt; &quot; and num2 is &quot; &lt;&lt; num2 &lt;&lt; endl;     genericSwap( num1, num2 );     cout &lt;&lt; &quot;After, num1 is &quot; &lt;&lt; num1 &lt;&lt; &quot; and num2 is &quot; &lt;&lt; num2 &lt;&lt; endl;     char c1 = &#39;a&#39;;     char c2 = &#39;z&#39;;     cout &lt;&lt; &quot;Before, c1 is &quot; &lt;&lt; c1 &lt;&lt; &quot; and c2 is &quot; &lt;&lt; c2 &lt;&lt; endl;     genericSwap( c1, c2 );     cout &lt;&lt; &quot;After, c1 is &quot; &lt;&lt; c1 &lt;&lt; &quot; and c2 is &quot; &lt;&lt; c2 &lt;&lt; endl;     ...     return( 0 );   }            </pre>  </div>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="typename.html">typename</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    this  </div>  <p>The this keyword is a pointer to the current object. All member  functions of a <a href="class.html">class</a> have a this  pointer.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="class.html">class</a><br>    <a href="operator.html">operator</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    throw  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  try {  statement list;  }  catch( typeA arg ) {  statement list;  }  catch( typeB arg ) {  statement list;  }  ...  catch( typeN arg ) {  statement list;  }</pre>  <p>The throw statement is part of the C++ mechanism for exception  handling. This statement, together with the <a href=  "try.html">try</a> and <a href="catch.html">catch</a> statements, the  C++ exception handling system gives programmers an elegant mechanism  for error recovery.</p>  <p>You will generally use a <a href="try.html">try</a> block to  execute potentially error-prone code. Somewhere in this code, a throw  statement can be executed, which will cause execution to jump out of  the <a href="try.html">try</a> block and into one of the <a href=  "catch.html">catch</a> blocks. For example:</p>  <pre class="example-code">   try {     cout &lt;&lt; &quot;Before throwing exception&quot; &lt;&lt; endl;     throw 42;     cout &lt;&lt; &quot;Shouldn&#39;t ever see this&quot; &lt;&lt; endl;   }   catch( int error ) {     cout &lt;&lt; &quot;Error: caught exception &quot; &lt;&lt; error &lt;&lt; endl;   }            </pre>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="catch.html">catch</a><br>    <a href="try.html">try</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    true  </div>  <p>The Boolean value of &quot;true&quot;.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="bool.html">bool</a><br>    <a href="false.html">false</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    try  </div>  <p>The try statement attempts to execute exception-generating code.  See the <a href="throw.html">throw</a> statement for more  details.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="catch.html">catch</a><br>    <a href="throw.html">throw</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    typedef  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  typedef existing-type new-type;</pre>  <p>The typedef keyword allows you to create a new type from an  existing type.</p>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    typeid  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  typeid( object );</pre>  <p>The typeid operator returns a reference to a type_info object that  describes `object`.</p>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    typename  </div>  <p>The typename keyword can be used to describe an undefined type or  in place of the <a href="class.html">class</a> keyword in a <a href=  "template.html">template</a> declaration.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="class.html">class</a><br>    <a href="template.html">template</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    union  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  union union-name {  public-members-list;      private:  private-members-list;  } object-list;</pre>  <p>A union is like a <a href="class.html">class</a>, except that all  members of a union share the same memory location and are by default  <a href="public.html">public</a> rather than <a href=  "private.html">private</a>. For example:</p>  <pre class="example-code">   union Data {     int i;     char c;   };           </pre>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="class.html">class</a><br>    <a href="struct.html">struct</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    unsigned  </div>  <p>The unsigned keyword is a data type modifier that is usually used  to declare unsigned <a href="int.html">int</a> variables. See the  <a href="../data_types.html">data types</a> page.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="bool.html">bool</a><br>    <a href="char.html">char</a><br>    <a href="double.html">double</a><br>    <a href="float.html">float</a><br>    <a href="int.html">int</a><br>    <a href="short.html">short</a><br>    <a href="signed.html">signed</a><br>    <a href="void.html">void</a><br>    <a href="wchar_t.html">wchar_t</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    using  </div>  <p>The using keyword is used to import a <a href=  "namespace.html">namespace</a> (or parts of a namespace) into the  current scope.</p>  <div class="related-examples-format">    Example code:  </div>  <div class="related-examples">    <p>For example, the following code imports the entire <em>std</em>    namespace into the current scope so that items within that    namespace can be used without a preceeding &quot;std::&quot;.</p>    <pre class="example-code"> using namespace std;           </pre>    <p>Alternatively, the next code snippet just imports a single    element of the <em>std</em> namespace into the current    namespace:</p>    <pre class="example-code"> using std::cout;               </pre>  </div>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="namespace.html">namespace</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    virtual  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  virtual return-type name( parameter-list );  virtual return-type name( parameter-list ) = 0;</pre>  <p>The virtual keyword can be used to create virtual functions, which  can be overridden by derived classes.</p>  <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 virtual 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 virtual function run.</li>  </ul>  <p>If the function is specified as a pure virtual function (denoted  by the = 0), it must be overridden by a derived class.</p>  <div class="related-examples-format">    Example code:  </div>  <div class="related-examples">    <p>For example, the following code snippet shows how a child class    can override a virtual method of its parent, and how a non-virtual    method in the parent cannot be overridden:</p>    <pre class="example-code">class Base {public: void nonVirtualFunc() {   cout &lt;&lt; &quot;Base: non-virtual function&quot; &lt;&lt; endl; } virtual void virtualFunc() {   cout &lt;&lt; &quot;Base: virtual function&quot; &lt;&lt; endl; }};              class Child : public Base {public: void nonVirtualFunc() {   cout &lt;&lt; &quot;Child: non-virtual function&quot; &lt;&lt; endl; } void virtualFunc() {   cout &lt;&lt; &quot;Child: virtual function&quot; &lt;&lt; endl; }};              int main() { Base* basePointer = new Child(); basePointer-&gt;nonVirtualFunc(); basePointer-&gt;virtualFunc(); return 0;}               </pre>    <p>When run, the above code displays:</p>    <pre class="example-code">Base: non-virtual functionChild: virtual function         </pre>  </div>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="class.html">class</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    void  </div>  <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>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="char.html">char</a><br>    <a href="double.html">double</a><br>    <a href="float.html">float</a><br>    <a href="int.html">int</a><br>    <a href="long.html">long</a><br>    <a href="short.html">short</a><br>    <a href="signed.html">signed</a><br>    <a href="unsigned.html">unsigned</a><br>    <a href="wchar_t.html">wchar_t</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    volatile  </div>  <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>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    wchar_t  </div>  <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>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="bool.html">bool</a><br>    <a href="char.html">char</a><br>    <a href="double.html">double</a><br>    <a href="float.html">float</a><br>    <a href="int.html">int</a><br>    <a href="short.html">short</a><br>    <a href="signed.html">signed</a><br>    <a href="unsigned.html">unsigned</a><br>    <a href="void.html">void</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    while  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  while( condition ) {  statement-list;  }</pre>  <p>The while keyword is used as a looping construct that will  evaluate the <em>statement-list</em> as long as <em>condition</em> is  true. Note that if the <em>condition</em> starts off as false, the  <em>statement-list</em> will never be executed. (You can use a  <a href="do.html">do</a> loop to guarantee that the statement-list  will be executed at least once.) For example:</p>  <pre class="example-code">   bool done = false;   while( !done ) {     ProcessData();     if( StopLooping() ) {       done = true;     }   }            </pre>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="break.html">break</a><br>    <a href="continue.html">continue</a><br>    <a href="do.html">do</a><br>    <a href="for.html">for</a><br>    <a href="if.html">if</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr></body></html>

⌨️ 快捷键说明

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