Recent piecemeal notes

Source: Internet
Author: User
    1. When a pointer of the character type is displayed, the pointer displays the string instead of the pointer content. to display the address in the character pointer, you only need to forcibly convert it to the void pointer.
    2. Only addresses can be stored in Pointer variables.
    3. The const at the end of the function header makes the function a constant function. The constant function cannot change the called object, mainly to ensure that the function does not accidentally change the object.
    4. Three methods of Constructor

1) initialize a class data member. The class data member cannot be initialized in the class declaration, because each object has its own variable, it must be initialized by the value required by the object being created.

2) constructor can also be used to verify data.

3) constructors must be used to allocate memory to objects.

Tip: constructor cannot have a return type, even if it is null. If any type of constructor is provided, the compiler will not provide the default constructor. Therefore, it is better to explicitly include one default constructor. 5. copy constructor.

1) execute the copy of values between simple variables and variables of all components of the object, which also becomes a bit copy

2) logical replication. The copied content is a pointer.

6. Use of the replication Constructor

1) when another object is used as a parameter to initialize an object

2) When the object is passed to the Function

3) when an object is returned from a function

8. The difference between a class and a structure: there is only one, that is, the data member is public by default in the structure, and private by default in the class.

9. If a function is called recursively, do not use an inline function.

10. Do not use the value assignment operator to initialize data members in the initialization list.

11. If you want to redefine the inherited private type to the protected type, rewrite it with the using and scope parsing operators. Example

 1   Class  Base
2 {
3 Protected :
4 Int Dam;
5 };
6 Class Derive: Private Base
7 {
8 Protected :
9 Using Base: dam;
10 };

12. Three conditions of polymorphism: inheritance, virtual function, pointer or reference

13. Static binding: When a pointer of the type base class is created, the compiler calls a function related to the base class of the pointer type no matter what object the Pointer Points to in the derived class. It is called static binding.

14. Virtual constructor is not allowed, but virtual constructor can be created. Virtual constructor cannot be created, but virtual constructor can be created. Why? For example, the base class dynamically allocates a floating point array P, and the derived class dynamically allocates a floating point array Q. When a base class pointer is used to point to a derived class object, this pointer can only see the base class, when this object is deleted, only the base class array is deleted, causing memory leakage to the derived class.

15. two situations in which a base-class function is declared as a pure virtual function:

1)
Cannot participate in the actions that a derived class may need

2)
You want to force each derived class to redefine this function.

Method: Virtual
Return_type identifier (parameter list) = 0;

16. abstract class: there must be at least one class of pure virtual function, which is used below

1)
Allowed Polymorphism

2)
You can define specific members that can be inherited in a derived class and do not need to be redefined.

3)
Provides a model for pure virtual functions that must be redefined in a derived class.

17. forced upward and downward conversions: When a derived class object is converted to a base class object, an upward forced conversion occurs. When the base class object is converted to a derived class object, a downward forced conversion occurs. At the same time, it is acceptable to forcibly convert the downward direction to the object pointer, but dynamic force conversion is required, that is, completed during the running. Syntax: dynamic_cast <type> (data );

18. OneProgramThe advantages and disadvantages of a function can be measured by the following principles: first, the module is independent, and second, the function has a single purpose.

19. constructor, destructor, non-member functions, and assignment operators are not inherited in the derived class and must be redefined.

20. The execution time of the base class constructor is earlier than that of the derived class constructor, And the Destructor is later than that of the derived class.

21. The call to the base class constructor should be in the initialization table section of the derived class.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.