📄 all.html
字号:
} int var; double var2; }; ... Base* b = new ("Base instance 1") Base;</pre> <p>If an int is 4 bytes and a double is 8 bytes, the above code generates the following output when run:</p> <pre class="example-code"> Logging an allocation of 12 bytes for new object 'Base instance 1'</pre> <div class="related-name-format"> Related topics: </div> <div class="related-content"> <a href="delete.html">delete</a><br> (Standard C Memory) <a href="../stdmem/free.html">free</a><br> (Standard C Memory) <a href="../stdmem/malloc.html">malloc</a> </div> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> operator </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> return-type class-name::operator#(parameter-list) { ... } return-type operator#(parameter-list) { ... }</pre> <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 <em>class-name</em> should be specified. For unary operators, <em>parameter-list</em> should be empty, and for binary operators, <em>parameter-list</em> should contain the operand on the right side of the operator (the operand on the left side is passed as <a href= "this.html">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 #, ##, ., :, .*, or ? tokens.</p> <div class="related-name-format"> Related topics: </div> <div class="related-content"> <a href="this.html">this</a> </div> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> private </div> <p>Private data of a class can only be accessed by members of that class, except when <a href="friend.html">friend</a> is used. The <a href="private.html">private</a> keyword can also be used to inherit a base class privately, which causes all <a href= "public.html">public</a> and <a href="protected.html">protected</a> members of the base class to become private members of the derived class.</p> <div class="related-name-format"> Related topics: </div> <div class="related-content"> <a href="class.html">class</a><br> <a href="protected.html">protected</a><br> <a href="public.html">public</a> </div> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> protected </div> <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 <a href= "public.html">public</a> and protected members of the base class to become protected members of the derived class.</p> <div class="related-name-format"> Related topics: </div> <div class="related-content"> <a href="class.html">class</a><br> <a href="private.html">private</a><br> <a href="public.html">public</a> </div> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> public </div> <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 <a href="protected.html">protected</a> members of the base class to become public and protected members of the derived class.</p> <div class="related-name-format"> Related topics: </div> <div class="related-content"> <a href="class.html">class</a><br> <a href="private.html">private</a><br> <a href="protected.html">protected</a> </div> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> register </div> <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> <div class="related-name-format"> Related topics: </div> <div class="related-content"> <a href="auto.html">auto</a> </div> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> reinterpret_cast </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> reinterpret_cast<type> (object);</pre> <p>The reinterpret_cast operator changes one data type into another. It should be used to cast between incompatible pointer types.</p> <div class="related-name-format"> Related topics: </div> <div class="related-content"> <a href="const_cast.html">const_cast</a><br> <a href="dynamic_cast.html">dynamic_cast</a><br> <a href="static_cast.html">static_cast</a> </div> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> return </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> return; return( value );</pre> <p>The return statement causes execution to jump from the current function to whatever function called the current function. An optional <em>value</em> can be returned. A function may have more than one return statement.</p> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> short </div> <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> <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="long.html">long</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"> signed </div> <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> <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="long.html">long</a><br> <a href="short.html">short</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"> sizeof </div> <p>The sizeof operator is a compile-time operator that returns the size, in bytes, of the argument passed to it. For example, the following code uses sizeof to display the sizes of a number of variables:</p> <pre class="example-code"> struct EmployeeRecord { int ID; int age; double salary; EmployeeRecord* boss; }; ... cout << "sizeof(int): " << sizeof(int) << endl << "sizeof(float): " << sizeof(float) << endl << "sizeof(double): " << sizeof(double) << endl << "sizeof(char): " << sizeof(char) << endl << "sizeof(EmployeeRecord): " << sizeof(EmployeeRecord) << endl; int i; float f; double d; char c; EmployeeRecord er; cout << "sizeof(i): " << sizeof(i) << endl << "sizeof(f): " << sizeof(f) << endl << "sizeof(d): " << sizeof(d) << endl << "sizeof(c): " << sizeof(c) << endl << "sizeof(er): " << sizeof(er) << endl;</pre> <p>When run, the above code displays this output:</p> <pre class="example-code"> sizeof(int): 4 sizeof(float): 4 sizeof(double): 8 sizeof(char): 1 sizeof(EmployeeRecord): 20 sizeof(i): 4 sizeof(f): 4 sizeof(d): 8 sizeof(c): 1 sizeof(er): 20</pre> <p>Note that sizeof can either take a variable type (such as <strong>int</strong>) or a variable name (such as <strong>i</strong> in the example above).</p> <p>It is also important to note that the sizes of various types of variables can change depending on what system you're on. Check out <a href="../data_types.html">a description of the C and C++ data types</a> for more information.</p> <p>The parentheses around the argument are not required if you are using sizeof with a variable type (e.g. sizeof(int)).</p> <div class="related-name-format"> Related topics: </div> <div class="related-content"> <a href="../data_types.html">C/C++ Data Types</a> </div> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> static </div> <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 <a href="class.html">class</a>, all instantiations of that class share one copy of the variable.</p> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> static_cast </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> static_cast<type> (object);</pre> <p>The static_cast keyword can be used for any normal conversion between types. No runtime checks are performed.</p> <div class="related-name-format"> Related topics: </div> <div class="related-content"> <a href="const_cast.html">const_cast</a><br> <a href="dynamic_cast.html">dynamic_cast</a><br> <a href="reinterpret_cast.html">reinterpret_cast</a> </div> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> struct </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> struct struct-name : inheritance-list { public-members-list; protected: protected-members-list; private: private-members-list; } object-list;</pre> <p>Structs are like `classes`, except that by default members of a struct are <a href="public.html">public</a> rather than <a href= "private.html">private</a>. In C, structs can only contain data and are not permitted to have inheritance lists. For example:</p> <pre class="example-code"> struct Date { int Day; int Month; int Year; }; </pre> <div class="related-name-format"> Related topics: </div> <div class="related-content"> <a href="class.html">class</a><br> <a href="union.html">union</a> </div> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> switch </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> switch( expression ) { case A: statement list; break; case B: statement list; break; ... case N: statement list; break; default: statement list; break; }</pre> <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.html">if</a>()...<a href="else.html">else</a> <a href= "if.html">if</a>()...<a href="else.html">else</a> <a href= "if.html">if</a>()... statements. <a href="break.html">break</a> statements are required between each <a href="case.html">case</a> statement, otherwise execution will "fall-through" to the next <a href="case.html">case</a> statement. The <a href= "default.html">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 class="example-code"> char keystroke = getch(); switch( keystroke ) { case 'a': case 'b': case 'c': case 'd': KeyABCDPressed(); break; case 'e': KeyEPressed(); break; default: UnknownKeyPressed(); break; } </pre> <div class="related-name-format"> Related topics: </div> <div class="related-content"> <a href="break.html">break</a><br> <a href="case.html">case</a><br> <a href="default.html">default</a><br> <a href="if.html">if</a> </div> </div> </td> </tr> </table></body></html><hr> <div class="name-format"> template </div> <div class="syntax-name-format"> Syntax: </div> <pre class="syntax-box"> template <class data-type> return-type name( parameter-list ) { statement-list; }</pre> <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 data-type for which many other <a href= "../data_types.html">data types</a> can be substituted.</p> <div class="related-examples-format"> Example code: </div> <div class="related-examples"> <p>For example, the following code uses a template to define a generic swap function that can swap two variables of any type:</p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -