From C to C ++
-Book notes on the design and evolution of C ++ language (3)
It cannot be said which language replaces which, but the appearance of a new language is bound with her new features. From C to C with a class to C ++, some new language features are gradually formed:
1. Virtual Functions
Make C ++ highly abstract into reality. That is to say, we don't have to worry about what the derived class really wants to do. In the parent class, we only define the function interface and delay the specific implementation to the derived class. The advantage of doing so is obvious, as shown in the example in the book: the parent class defines an interface draw (), no matter how the derived class will "Draw ", you only need to define draw () in the derived class and specify the behavior of "painting" by yourself, you can find the draw () in the derived class along the hierarchy of inheritance (), although on the surface, it is called the draw () of the parent class (). In this way, you can use virtual functions to implement modularity. The disadvantage is that the implementation of the compiler becomes more and more difficult, and the generated code will become relatively large, and the efficiency will be affected.
2. Overload
Reload makes the language concise. First, some functions with the same meaning can appear with the same name. The difference lies in the parameter and return type. Second, the user-defined type can be used to simulate the built-in operation mode. In terms of efficiency, it seems that there is no impact on us :)
3. Constants
Try to use const and inline instead of # define, which is the difference between C ++ and C. Why? I think Clause 1 in <strong tive C ++> is clear.
4. Storage Management and type check
These issues make C ++ more secure. <strong tive C ++>.
5. Statement Declaration
I think this is a big improvement, although Bjarne thinks this is a secondary feature. Learning the C language is that variables are always declared without returning to the beginning of the function. The key is to recycle the temporary variable space, as mentioned in