📄 keywords_details.html
字号:
for( ; ; ) { // loop forever! }</pre> <i>Related topics:</i><br> <strong><a href="#do">do</a>, <a href="#while">while</a></strong> <hr> <h2><a name="friend">friend</a></h2> <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> <hr> <h2><a name="goto">goto</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> goto labelA; ... labelA:</pre> </td> </tr> </table> <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">for</a> loop, compared to the space and time that extra break logic would consume.</p> <i>Related topics:</i><br> <strong><a href="#break">break</a></strong> <hr> <h2><a name="if">if</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> if( conditionA ) { statement-listA; } else if( conditionB ) { statement-listB; } ... else { statement-listN; }</pre> </td> </tr> </table> <p>The if construct is a branching mechanism that allows different code to execute under different conditions. The <i>conditions</i> are evaluated in order, and the <i>statement-list</i> of the first condition to evaluate to true is executed. If no conditions evaluate to true and an <strong>else</strong> statement is present, then the statement list within the else block will be executed. All of the else blocks are optional.</p> <i>Related topics:</i><br> <strong><a href="#else">else</a>, <a href="#for">for</a>, <a href="#while">while</a></strong> <hr> <h2><a name="inline">inline</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> inline int functionA( int i ) { ... }</pre> </td> </tr> </table> <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">static</a> data, loops, <a href="#switch">switches</a>, 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> <hr> <h2><a name="int">int</a></h2> <p>The int keyword is used to declare integer variables. Also see the <a href="data_types.html">data types</a> page.</p> <hr> <h2><a name="long">long</a></h2> <p>The long keyword is a data type modifier that is used to declare long integer variables. See the <a href="data_types.html">data types</a> page.</p> <i>Related topics:</i><br> <strong><a href="#short">short</a></strong> <hr> <h2><a name="mutable">mutable</a></h2> <p>The mutable keyword overrides any enclosing <a href="#const">const</a> statement. A mutable member of a const object can be modified.</p> <hr> <h2><a name="namespace">namespace</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> namespace name { declaration-list; }</pre> </td> </tr> </table> <p>The namespace keyword allows you to create a new scope. The <i>name</i> is optional, and can be omitted to create an unnamed namespace. Once you create a namespace, you'll have to refer to it explicitly or use the <a href="#using">using</a> keyword. For example:</p><pre> namespace CartoonNameSpace { int HomersAge; void incrementHomersAge() { HomersAge++; } } int main() { ... CartoonNameSpace::HomersAge = 39; CartoonNameSpace::incrementHomersAge(); cout << CartoonNameSpace::HomersAge << endl; ... }</pre> <br> <br> <hr> <h2><a name="new">new</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> pointer = new type; pointer = new type( initializer ); pointer = new type[size];</pre> </td> </tr> </table> <p>The new operator allocates a new chunk of memory to hold a variable of type <i>type</i> and returns a pointer to that memory. An optional <i>initializer</i> can be used to initialize the memory. Allocating arrays can be accomplished by providing a <i>size</i> parameter in brackets.</p> <i>Related topics:</i><br> <strong><a href="#delete">delete</a></strong> <hr> <h2><a name="operator">operator</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> return-type class-name::operator#(parameter-list) { ... } return-type operator#(parameter-list) { ... }</pre> </td> </tr> </table> <p>The operator keyword is used to overload operators. The sharp sign (#) listed above in the syntax description represents the operator which will be overloaded. If part of a class, the <i>class-name</i> should be specified. For unary operators, <i>parameter-list</i> should be empty, and for binary operators, <i>parameter-list</i> should contain the operand on the right side of the operator (the operand on the left side is passed as <a href="#this">this</a>).</p> <p>For the non-member operator overload function, the operand on the left side should be passed as the first parameter and the operand on the right side should be passed as the second parameter.</p> <p>You cannot overload the <strong>#</strong>, <strong>##</strong>, <strong>.</strong>, <strong>:</strong>, <strong>.*</strong>, or <strong>?</strong> tokens.</p> <hr> <h2><a name="private">private</a></h2> <p>Private data of a class can only be accessed by members of that class, except when <a href= "#friend">friend</a> is used. The private keyword can also be used to inherit a base class privately, which causes all public and protected members of the base class to become private members of the derived class.</p> <i>Related topics:</i><br> <strong><a href="#protected">protected</a>, <a href="#public">public</a></strong> <hr> <h2><a name="protected">protected</a></h2> <p>Protected data are private to their own class but can be inherited by derived classes. The protected keyword can also be used as an inheritance specifier, which causes all public and protected members of the base class to become protected members of the derived class.</p> <i>Related topics:</i><br> <strong><a href="#private">private</a>, <a href="#public">public</a></strong> <hr> <h2><a name="public">public</a></h2> <p>Public data in a class are accessible to everyone. The public keyword can also be used as an inheritance specifier, which causes all public and protected members of the base class to become public and protected members of the derived class.</p> <i>Related topics:</i><br> <strong><a href="#private">private</a>, <a href="#protected">protected</a></strong> <hr> <h2><a name="register">register</a></h2> <p>The register keyword requests that a variable be optimized for speed, and fell out of common use when computers became better at most code optimizations than humans.</p> <i>Related topics:</i><br> <strong><a href="#auto">auto</a></strong> <hr> <h2><a name="reinterpret_cast">reinterpret_cast</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> reinterpret_cast<type> (object);</pre> </td> </tr> </table> <p>The reinterpret_cast operator changes one data type into another. It should be used to cast between incompatible pointer types.</p> <i>Related topics:</i><br> <strong><a href="#const_cast">const_cast</a>, <a href="#dynamic_cast">dynamic_cast</a>, <a href= "#static_cast">static_cast</a></strong> <hr> <h2><a name="return">return</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> return; return( value );</pre> </td> </tr> </table> <p>The return statement causes execution to jump from the current function to whatever function called the current function. An optional <i>value</i> can be returned. A function may have more than one return statement.</p> <hr> <h2><a name="short">short</a></h2> <p>The short keyword is a data type modifier that is used to declare short integer variables. See the <a href="data_types.html">data types</a> page.</p> <i>Related topics:</i><br> <strong><a href="#long">long</a></strong> <hr> <h2><a name="signed">signed</a></h2> <p>The signed keyword is a data type modifier that is usually used to declare signed char variables. See the <a href="data_types.html">data types</a> page.</p> <i>Related topics:</i><br> <strong><a href="#unsigned">unsigned</a></strong> <hr> <h2><a name="sizeof">sizeof</a></h2> <p>The sizeof operator is a compile-time operator that returns the size, in bytes, of the argument passed to it.</p> <hr> <h2><a name="static">static</a></h2> <p>The static data type modifier is used to create permanent storage for variables. Static variables keep their value between function calls. When used in a class, all instantiations of that class share one copy of the variable.</p> <hr> <h2><a name="static_cast">static_cast</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> static_cast<type> (object);</pre> </td> </tr> </table> <p>The static_cast keyword can be used for any normal conversion between types. No runtime checks are performed.</p> <i>Related topics:</i><br> <strong><a href="#const_cast">const_cast</a>, <a href="#dynamic_cast">dynamic_cast</a>, <a href= "#reinterpret_cast">reinterpret_cast</a></strong> <hr> <h2><a name="struct">struct</a></h2> <i>Syntax:</i> <table bgcolor="#ccccff"> <tr> <td><pre> struct struct-name : inheritance-list { public-members-list; protected: protected-members-list; private: private-members-list; } object-list;</pre> </td> </tr> </table> <p>Structs are like <a href="#class">classes</a>, except that by default members of a struct are public rather than private. In C, structs can only contain data and are not permitted to have inheritance lists. For example:</p><pre> struct Date { int Day; int Month; int Year; };</pre> <i>Related topics:</i><br> <strong><a href="#class">class</a>, <a href="#union">union</a></strong> <hr>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -