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
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
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.
#. Set copy constructors or copy assignment operators to private and do
not implement them.
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
declaration is ``noexcept``, which enables the compiler to optimize the
function to the maximum extent, for example, reducing the execution
paths and improving the efficiency of exiting when an error occurs. 2.
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 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:
**Reasons:**
* 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.
* 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
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
...
...
@@ -3028,9 +3006,9 @@ The disadvantages of template proramming are as follows:
the transformation makes sense in all of them.
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
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
user-facing headers are readable. And you should write sufficiently
detailed comments for code that uses templates.
...
...
@@ -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.
};
**Summary** 1. When defining the virtual function for the first time
based on the base class, use the keyword ``virtual``. 2. When overriding
the virtual function by a subclass in a base class, including
destructors, use the keyword ``override`` or ``final`` instead of
``virtual``. 3. For the non-virtual function, do not use ``virtual`` or
``override``.
**Summary**
#. When defining the virtual function for the first time based on the base class, use the keyword ``virtual``.
#. When overriding the virtual function by a subclass in a base class, including destructors, use the keyword ``override`` or ``final`` instead of ``virtual``.
#. For the non-virtual function, do not use ``virtual`` or ``override``.
Rule: 10.1.2 Use the keyword ``delete`` to delete functions.