"C ++ Primer" reading note 7

zhaozj2021-02-16  69

Note: Section 2.4

In the previous section, the author carries us to build a Class. As the author said: it can meet some users, but we all know that our world is diverse. Of course, demand will also be divided into different levels, but all kinds of resources produced are extremely limited, so the pursuit of work efficiency has become the main goal of our technology development.

For programming work. The efficiency is mainly from the reuse of the code. Because of the development of computer hardware technology, the programmer can reasonably ignore some code execution efficiency (not completely ignored). For the reuse of the code, according to the author's description, I want to understand him into two aspects of effort to divide the method (function).

At the end of the caller. We want to write a code that determines the specific implementation method of its code itself by the computer. As written on the book, when we write:

INT x = max (a, b);

We hope that the computer determines the MAX () instance of the Call according to the data type of A and B. It is overloaded. (In fact, this is the content of the next section. But I think I will put it here to summarize more beneficial to understand its role and essence)

At one end being called. On the one hand, we hope that our code can be called by different programs. On the other hand, we also hope that your code can respond according to the specific situation of the called end, which has created great technology. The former has led to the birth of OO theory, and the latter leads out generic design ideas.

I finally saw Oo, huh, huh. In the afternoon, I found that OO did not imagine that it was so complicated, so mysterious. Is it not difficult for him? NO, not this, this is completely due to our great author, let us go from the beginning, start from the root cause of technology. It is easier to understand the nature of technology. We will be surprised to find that this is as follows:

1. Different different object methods of similar objects different? OK, the virtual function came into being.

2. Simply join several functions to form another related class? OK, the inheritance mechanism is for this.

3. If you still want the new class, you will. Many inheritance.

It can be seen that under this thought, many difficult things are difficult to understand. It's more simple to change.

Of course, we don't forget these convenience while facilitating programming. Sometimes we have to go back and consider these troublesome questions. The author also provides some direction of thinking, such as. Inline technology, etc., but as mentioned above, these are not the most important.

Finally, I would like to explain. From Section 2.3, until this chapter ends, all content here is worth playing. There will be different feelings every time you reread. It is highly recommended to continue to read this content in the future learning, you will find the need to do this, just as I avoided the code details level technology.

转载请注明原文地址:https://www.9cbs.com/read-16075.html

New Post(0)