C++ notes 6.3

1.a=5<<2 then a=20 means to shift two bits to the left and multiply by 4

2. Using objects to call virtual functions will not reflect true polymorphism, and only use base class pointers or references to point to derived class objects.
In the base class, once a member method is defined as a virtual function, at the same time, if the function is overloaded in the derived class, then when the derived class object is called, the member function in the derived class is called instead of the base Member functions in the class.

3.①The break statement can be used in a loop statement to terminate the current loop; it can also be used to end a case in a switch statement.
②The continue statement can only be used for loop statements.
③Unconditional jump statements include break, continue, return, and goto.
④In the switch statement, continue is used to make the execution flow jump out of the switch statement.
In the loop statement, break is used to make the execution flow unconditionally jump out of the loop body of this layer.
The function of continue is to end this loop, and then proceed to determine whether to execute the loop next time.
The jump scope of break and continue statements is clear.

4. You can use the derived class object to initialize the base class object or pointer
① assign the derived class object to the base class object
② assign the address of the derived class object to the base class pointer
③ use the derived class object to initialize the reference of the base class object

Derived class objects can only access members of the base class if the members of the base class are not covered by the derived class.

5. Floating point types cannot be exactly equal

6. Insert picture description here
7.①A trait includes enum, typedef, template partial specialization (template partial specialization)
②Typedef defines different type definitions of each class ③Template partial specialization
is used to implement different functions of each class
④When function, Some parts of classes or some encapsulated general algorithms will have different processing or logic due to different data types. Traits will be a good solution.

Guess you like

Origin blog.csdn.net/qq_43729554/article/details/106535901
Recommended