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

📄 all.html

📁 从www.CppReference.com打包的C++参考手册
💻 HTML
📖 第 1 页 / 共 4 页
字号:
  </tr>  </table></body></html><hr>  <div class="name-format">    enum  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  enum name {name-list} var-list;</pre>  <p>The enum keyword is used to create an enumerated type named name  that consists of the elements in <em>name-list</em>. The  <em>var-list</em> argument is optional, and can be used to create  instances of the type along with the declaration.  For example, the  following code creates an enumerated type for colors:</p>  <div class="related-examples">    <pre class="example-code">   enum ColorT {red, orange, yellow, green, blue, indigo, violet};   ...   ColorT c1 = indigo;   if( c1 == indigo ) {     cout &lt;&lt; &quot;c1 is indigo&quot; &lt;&lt; endl;   }            </pre></div>  <p>In the above example, the effect of the enumeration is to  introduce several new constants named <em>red</em>, <em>orange</em>,  <em>yellow</em>, etc.  By default, these constants are assigned  consecutive integer values starting at zero.  You can change the  values of those constants, as shown by the next example:</p>  <div class="related-examples">    <pre class="example-code">   enum ColorT { red = 10, blue = 15, green };   ...   ColorT c = green;   cout << "c is " << c << endl;</pre></div>  <p>When executed, the above code will display the following  output:</p>  <div class="related-examples">    <pre class="example-code">   c is 16</pre></div>  <p>Note that the above examples will only work with C++ compilers.  If you're working in regular C, you will need to specify the  <em>enum</em> keyword whenever you create an instance of an  enumerated type:  <div class="related-examples">    <pre class="example-code">   enum ColorT { red = 10, blue = 15, green };   ...   enum ColorT c = green;   // note the aditional enum keyword   printf( "c is %d\n", c );</pre></div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    explicit  </div>  <p>When a constructor is specified as explicit, no automatic  conversion will be used with that constructor -- but parameters passed to the constructor may still be converted.  For example:</p>  <pre class="example-code">  struct foo {    explicit foo( int a )      : a_( a )    { }    int a_;  };  int bar( const foo & f ) {    return f.a_;   }  bar( 1 );  // fails because an implicit conversion from int to foo             // is forbidden by explicit.  bar( foo( 1 ) );  // works -- explicit call to explicit constructor.  bar( foo( 1.0 ) );  // works -- explicit call to explicit constructor                      // with automatic conversion from float to int.</pre>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    export  </div>  <p>The export keyword is intended to allow definitions of C++  templates to be separated from their declarations.  While officially  part of the C++ standard, the export keyword is only supported by a  few compilers (such as the Comeau C++ compiler) and is not supported  by such mainstream compilers as GCC and Visual C++.  </p>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    extern  </div>  <p>The extern keyword is used to inform the compiler about variables  declared outside of the current scope. Variables described by extern  statements will not have any space allocated for them, as they should  be properly defined elsewhere.</p>  <p>Extern statements are frequently used to allow data to span the  scope of multiple files.</p>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    false  </div>  <p>The Boolean value of &quot;false&quot;.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="bool.html">bool</a><br>    <a href="true.html">true</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    float  </div>  <p>The float keyword is used to declare floating-point 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="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="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">    for  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  for( initialization; test-condition; increment ) {  statement-list;  }</pre>  <p>The for construct is a general looping mechanism consisting of 4  parts:</p>  <ol>    <li>the initialization, which consists of 0 or more comma-delimited    variable initialization statements</li>    <li>the test-condition, which is evaluated to determine if the    execution of the for loop will continue</li>    <li>the increment, which consists of 0 or more comma-delimited    statements that increment variables</li>    <li>and the statement-list, which consists of 0 or more statements    that will be executed each time the loop is executed.</li>  </ol>  <p>For example:</p>  <pre class="example-code">   for( int i = 0; i &lt; 10; i++ ) {     cout &lt;&lt; &quot;i is &quot; &lt;&lt; i &lt;&lt; endl;   }   int j, k;   for( j = 0, k = 10;        j &lt; k;        j++, k-- ) {     cout &lt;&lt; &quot;j is &quot; &lt;&lt; j &lt;&lt; &quot; and k is &quot; &lt;&lt; k &lt;&lt; endl;   }   for( ; ; ) {     // loop forever!   }            </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="if.html">if</a><br>    <a href="while.html">while</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    friend  </div>  <p>The friend keyword allows classes or functions not normally  associated with a given class to have access to the private data of  that class.</p>  <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">    goto  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  goto labelA;  ...  labelA:</pre>  <p>The goto statement causes the current thread of execution to jump  to the specified label. While the use of the goto statement is  generally <a href="http://www.acm.org/classics/oct95/">considered  harmful</a>, it can occasionally be useful. For example, it may be  cleaner to use a goto to break out of a deeply-nested <a href=  "for.html">for</a> loop, compared to the space and time that extra  <a href="break.html">break</a> logic would consume.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="break.html">break</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    if  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  if( conditionA ) {    statement-listA;  }  else if( conditionB ) {    statement-listB;  }  ...  else {    statement-listN;  }</pre>  <p>The if construct is a branching mechanism that allows different  code to execute under different conditions. The conditions are  evaluated in order, and the statement-list of the first condition to  evaluate to true is executed. If no conditions evaluate to true and  an <a href="else.html">else</a> statement is present, then the  statement list within the else block will be executed. All of the  <a href="else.html">else</a> blocks are optional.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="else.html">else</a><br>    <a href="for.html">for</a><br>    <a href="switch.html">switch</a><br>    <a href="while.html">while</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    inline  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  inline int functionA( int i ) {  ...  }</pre>  <p>The inline keyword requests that the compiler expand a given  function in place, as opposed to inserting a call to that function.  Functions that contain <a href="static.html">static</a> data, loops,  <a href="switch.html">switch</a> statements, or recursive calls  cannot be inlined. When a function declaration is included in a class  declaration, the compiler should try to automatically inline that  function.</p>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    int  </div>  <p>The int keyword is used to declare integer 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="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="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">    long  </div>  <p>The long keyword is a data type modifier that is used to declare  long integer variables. For more information on long, 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>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    mutable  </div>  <p>The mutable keyword overrides any enclosing <a href=  "const.html">const</a> statement. A mutable member of a <a href=  "const.html">const</a> object can be modified.</p>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="const.html">const</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    namespace  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  namespace name {  declaration-list;  }</pre>  <p>The namespace keyword allows you to create a new scope. The name  is optional, and can be omitted to create an unnamed namespace. Once  you create a namespace, you&#39;ll have to refer to it explicitly or  use the <a href="using.html">using</a> keyword.</p>  <div class="related-examples-format">    Example code:  </div>  <div class="related-examples">    <pre class="example-code">   namespace CartoonNameSpace {     int HomersAge;     void incrementHomersAge() {       HomersAge++;     }   }   int main() {     ...     CartoonNameSpace::HomersAge = 39;     CartoonNameSpace::incrementHomersAge();     cout &lt;&lt; CartoonNameSpace::HomersAge &lt;&lt; endl;     ...   }            </pre>  </div>  <div class="related-name-format">    Related topics:  </div>  <div class="related-content">    <a href="using.html">using</a>  </div>  </div>  </td>    </tr>  </table></body></html><hr>  <div class="name-format">    new  </div>  <div class="syntax-name-format">    Syntax:  </div>  <pre class="syntax-box">  pointer = new type;  pointer = new type( initializer );  pointer = new type[size];  pointer = new( arg-list ) type...</pre>  <p>The new operator (valid only in C++) allocates a new chunk of  memory to hold a variable of type <em>type</em> and returns a  pointer to that memory.  An optional initializer can be used to  initialize the memory.  Allocating arrays can be accomplished by  providing a <em>size</em> parameter in brackets.</p>  <p>The optional <em>arg-list</em> parameter can be used with any of  the other formats to pass a variable number of arguments to an  overloaded version of new().  For example, the following code shows  how the new() function can be overloaded for a class and then passed  arbitrary arguments:</p>  <pre class="example-code">  class Base {  public:    Base() { }    void *operator new( unsigned int size, string str ) {      cout &lt;&lt; "Logging an allocation of " &lt;&lt; size &lt;&lt; " bytes for new object '" &lt;&lt; str &lt;&lt; "'" &lt;&lt; endl;      return malloc( size );

⌨️ 快捷键说明

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