This book is really good. We recommend you take a look.
Chapter 4 prerequisites
1. A Brief History of C ++
The PASCAL Language was launched in 1968 and C was launched in 1969. Both languages are examples of structured programming.
2. c ++ and general programming
3. c ++ Origin
4. Portability and standards
Chapter 4 start to learn C ++
1. Variable Declaration
2. Use library functions
The header file is used to provide a function prototype, so that the program can compile and generate the correct target file, so that it is possible to connect to the correct file when linking, however, sometimes the linker cannot find the correct link path, which requires a specific search path.
For example, in Linux, the standard input and output functions are in libc. in database A, the linker will automatically find and link, but for the math library, it is not a part of the standard library, in libm. -LM must be used to specify a link.
Chapter 4 composite type
1. array type
2. Each time a string is read
3. pointer and C ++ Basic Principles
The difference between object-oriented programming and traditional process programming is that OOP emphasizes decision-making in the runtime stage rather than the compilation stage. The running stage refers to the program being run, and the compiling stage refers to the compilation of the program.
Int * PT;
PT = (int *) 0xb8000000;
4. Stack, heap, and memory leakage
Chapter 1 loop and relational expressions
1. Expression
A c ++ expression is a combination of values or operators. Each C ++ expression has a value.
2. Comparison of C-style strings
Chapter 2 Memory Model and namespace
1. Functions and linking
2. Language linking
3. Anonymous namespace
In comparison with C ++, it is recommended that anonymous namespaces be used to replace static variables with links.
The C ++ standard does not approve the use of the keyword static in the namespace and global scope.
Chapter 3 objects and Classes
Chapter 1 usage
1. type conversion
2. Call the bootstrap function before the main function.
Chapter 4 class and Dynamic Allocation
1. Implicit member functions
2. Use the new operator in the constructor
3. Some descriptions of objects are returned.
4. pointer and object Summary
5. layout the new operator (positioning the new expression C ++ primer, the third edition)
In general, new is responsible for finding a memory block that meets the requirements in the heap memory. The new operator also has a variant: the placement new operator, which allows you to specify the location of the memory to be used. Programmers can use this feature to set their memory management procedures or process hardware that needs to be accessed through a specific address. To make placement new, you must first include the header file new.
When the new layout is used for allocation, the original address is allocated as follows:
Int * P3 = new (buffer) int [20];
At this time, the P3 address space is the same as the P2 address space. However, you can change the allocation space address by changing the initial address, for example:
Int * P4 = new (buffer + 20 * sizeof (INT) int [20];
At this time, the P4 address does not overlap with the above.
Note that delete can be used with the regular New operator instead of the layout new operator. Therefore, you only need to release the buffer space instead of Delete to release P3 or P4. If the buffer is the space applied for in the static zone, the program automatically releases the buffer, if the buffer is a dynamically applied space, use Delete to release it.
The built-in type is used here. If a new problem occurs when an object is used. Because the object involves the issue of calling the destructor.
In general, the system automatically calls the Destructor for objects statically allocated. For objects created on the stack, the system does not automatically call the destructor. It is common to use new to dynamically allocate objects. In this case, when Delete is used to release memory space, the Destructor will be automatically called. A rare exception is that when we use the new layout, we need to call the Destructor that we display.
For example, PC3-> ~ Justtesting ();
PC1-> ~ Justtesting ();
Chapter 4 class inheritance
1. Virtual member functions and dynamic Association
2. Virtual Functions
3. Use of protected: Singleton Mode
4. Inheritance and dynamic memory allocation
How does inheritance interact with dynamic memory allocation? For example, if the base class uses dynamic memory allocation and the assignment and copy constructor are redefined, how does this affect the implementation of the derived class? The answer to this question depends on the attributes of the derived class. If the derived class also uses dynamic memory allocation, you need to learn a few new tips. Let's take a look at these two situations:
(1) The derived class does not use new
Do the derived classes need to define the Destructor for the display, and copy the constructor and the value assignment operator?
No!
First, check whether a destructor is required. If no destructor is defined, the compiler will define a default constructor that does not execute any operations. In fact, the default constructor of a derived class always needs to perform some operations: execute its own code and call the basic class destructor. Because we assume that the members of the derived class do not need to perform any special operations, the default destructor is appropriate.
Let's look at the replication constructor. By default, the copy constructor executes member replication, which is not suitable for dynamic memory allocation, but is suitable for new derived class members. Therefore, you only need to consider the inherited base class objects. You must know that member replication uses the corresponding replication method based on the data type. Therefore, when copying class members or inherited Class components, the replication constructor of this class is used. Therefore, the default copy constructor of a derived class uses the display copy constructor of the base class to copy the base class member of the object of the derived class. Therefore, the default copy constructor is suitable for the new derived class.
The same applies to assignments.
(2). the derived class uses new.
When both the base class and the derived class adopt dynamic memory allocation, the destructor, the copy constructor, and the value assignment operator of the derived class must use the base class method to process the base class elements. This requirement is met in three different ways.
- This is automatically completed for destructor;
- For constructors, this is done by calling the copy constructor of the base class in the initialization member list. Otherwise, the default constructor of the base class is automatically called.
- For the replication operator, this is done by calling the assignment operator of the base class displayed by the scope resolution operator.
5. Summary of C ++ Class Functions
Chapter 2 code reuse in C ++
1. Multiple inheritance and virtual base classes
Chapter 4 youyuan, exceptions, and others
1. Membership functions
The Forward Declaration of classes involved here
2. Stack decommission
3. rtti runtime type recognition
Chapter 4 input, output, and files
1. Read characters and strings
2. Binary and text files