Rule 3.13.1 The number sign (#) that starts a preprocessor directive must be at the beginning of the line and can be indented in nested preprocessor directives.
Rule 3.13.1 The number sign (#) that starts a preprocessor directive must be at the beginning of the line and can be indented in nested preprocessor directives.
The number sign (#) that starts a preprocessor directive must be at the
The number sign (#) that starts a preprocessor directive must be at the
beginning of the line even through the preprocessor directive is inside
beginning of the line even through the preprocessor directive is inside
...
@@ -1795,8 +1795,7 @@ Rule 7.1.3 If copy/move constructors and copy/move assignment operators are not
...
@@ -1795,8 +1795,7 @@ Rule 7.1.3 If copy/move constructors and copy/move assignment operators are not
Note: If users do not define it, the compiler will generate copy constructors and copy assignment operators, move constructors and move assignment operators (move semantic functions will be available in versions later than C++ 11). If we do not use copy constructors or copy
Note: If users do not define it, the compiler will generate copy constructors and copy assignment operators, move constructors and move assignment operators (move semantic functions will be available in versions later than C++ 11). If we do not use copy constructors or copy
assignment operators, explicitly delete them.
assignment operators, explicitly delete them.
#. Set copy constructors or copy assignment operators to private and do
Set copy constructors or copy assignment operators to private and do not implement them.
**Reasons:** 1. If the function does not throw an exception, the
**Reasons:**
declaration is ``noexcept``, which enables the compiler to optimize the
* If the function does not throw an exception, the declaration is ``noexcept``, which enables the compiler to optimize thefunction to the maximum extent, for example, reducing the execution paths and improving the efficiency of exiting when an error occurs.
function to the maximum extent, for example, reducing the execution
* For STL containers such as ``vector``, to ensure the interface robustness, if the ``move`` constructor of saved items is not declared as ``noexcept``, the ``copy machanism`` instead of the ``move machanism`` is used when the items are removed from the container. This would cause
paths and improving the efficiency of exiting when an error occurs. 2.
performance loss risks. If the function does not throw an exception, or a program does not intercept and process an
For STL containers such as ``vector``, to ensure the interface
exception thrown by the function, new ``noexcept`` keywords can be used to modify the function, indicating that the function does not throw an
robustness, if the ``move`` constructor of saved items is not declared
exception or the thrown exception is not intercepted or processed. For example:
as ``noexcept``, the ``copy machanism`` instead of the
``move machanism`` is used when the items are removed from the
container. This would cause performance loss risks. If the function does
not throw an exception, or a program does not intercept and process an
exception thrown by the function, new ``noexcept`` keywords can be used
to modify the function, indicating that the function does not throw an
exception or the thrown exception is not intercepted or processed. For
example:
.. code:: cpp
.. code:: cpp
...
@@ -3028,9 +3006,9 @@ The disadvantages of template proramming are as follows:
...
@@ -3028,9 +3006,9 @@ The disadvantages of template proramming are as follows:
the transformation makes sense in all of them.
the transformation makes sense in all of them.
Therefore, it is recommended that \_\_ template programming be used only
Therefore, it is recommended that \_\_ template programming be used only
in a small number of basic components and basic data structure__. When
in a small number of basic components and basic data structure. When
using the template programming, minimize the **complexity as much as
using the template programming, minimize the **complexity as much as
possible, and** avoid exposing the template__. It is better to hide
possible, and** avoid exposing the template. It is better to hide
programming as an implementation detail whenever possible, so that
programming as an implementation detail whenever possible, so that
user-facing headers are readable. And you should write sufficiently
user-facing headers are readable. And you should write sufficiently
detailed comments for code that uses templates.
detailed comments for code that uses templates.
...
@@ -3162,12 +3140,10 @@ modify the overridden function when there are multiple subclasses.
...
@@ -3162,12 +3140,10 @@ modify the overridden function when there are multiple subclasses.
void Bar() override; // Compilation failed: base::Bar is not a virtual function.
void Bar() override; // Compilation failed: base::Bar is not a virtual function.
};
};
**Summary** 1. When defining the virtual function for the first time
**Summary**
based on the base class, use the keyword ``virtual``. 2. When overriding
#. When defining the virtual function for the first time based on the base class, use the keyword ``virtual``.
the virtual function by a subclass in a base class, including
#. When overriding the virtual function by a subclass in a base class, including destructors, use the keyword ``override`` or ``final`` instead of ``virtual``.
destructors, use the keyword ``override`` or ``final`` instead of
#. For the non-virtual function, do not use ``virtual`` or ``override``.
``virtual``. 3. For the non-virtual function, do not use ``virtual`` or
``override``.
Rule: 10.1.2 Use the keyword ``delete`` to delete functions.
Rule: 10.1.2 Use the keyword ``delete`` to delete functions.