The biggest difficulty in learning C + + programming languages

Source: Internet
Author: User
Tags inheritance object model

One of the difficulty degrees

"C + + is a difficult language to learn to use," said the word I believe many people are very happy. C + + Learning difficulty, one of the language itself too much "screen", the other is "paradigm shift" (thinking mode of transfer).

Traditional languages such as C, Pascal, Basic, Fortran ..., in addition to the appearance of a slightly different look, basically is a function call to call to go, the same, very easy to grasp. The action you want to do is clearly seen in the code. What you can't see is that the compiler adds a little bit of code (prologue and epilogue) to your stack, which basically does the housekeeping work, you don't see it, it doesn't matter, it doesn't affect your thinking about the logic of the program.

C + + is not the same, C + + has too much and the logic of the program is closely related to the compiler for us to add. In other words, C + + compilers are "overweight" for us. If you do not know this section, learning C + + is like a smoke and mirrors, fog, not fog, flowers and flowers.

What code does the compiler add to our C + + program? A lot! When an object is born, the ctor is aroused and the dtor is aroused when the object dies, which is the result of the overweight. ctor set VTPR and VTBL, which is also the result of the overweight. When a new single object produces an array of memory block cookie,new objects, an internal structure is generated that records the object size and class ctor ... and it's all behind the scenes. It can be said that all the code-related actions that are not visible in code but must be completed are the result of a C + + compiler.

When "Inheritance" occurs, the whole situation becomes slightly more complicated. "Multiple inheritance" is more complex, and "virtual inheritance" is more complex.

These cloth behind the scenes of the theme, can be categorized as the so-called C + + object Model (object models). If you do not know the underlying mechanism, you can only destructors the rules of "make-virtual in base classes" or "Never treat arrays polymorphically" without understanding its rationale. With one thing, but do not understand the truth of it, Lin Yutang said: "Not clever." Only know how, do not know why.

Difficulty of two difficulties

The second learning difficulty for C + + is "paradigm shift" (the transfer of Thinking mode). Don't say that you design classes, light use other people's classes, all is a kind of thinking mode and behavior pattern transfer. MFC (or OWL or VCL) programmer must be able to appreciate and appreciate the meaning.

What is the relationship between your code and the framework using the so-called application framework (a large, cohesive, object-oriented class library with object-oriented public infrastructure)? What is the meaning and value of a large stack of rewritten virtual functions provided by the framework? Why is it that the various beautiful properties of the framework and the various algorithms can be implemented in our own design of class types? When the framework is designed, it is not known that we exist. This is the power of the multi-type (polymorphism) in object-oriented.

The C + + object model, described earlier, is part of the low level of programming, where the thought-mode transfer is a high level of programming. The ability to play the power of new thinking patterns most vividly when pushing object-oriented polymorphism (multimodal) and generalization (generics). If you do not use these two features, equal to the C + + Baoshan but empty-handed.

Repeated tempering, cyclic oscillation

Imagine C + + is used to solve the problem of the knife, to its strong, to its sharp, it must undergo a number of tempering, in between high fever and sudden cold-lian.

After beginners C + + syntax (syntax), you should try to experience polymorphism (basically, the use of virtual functions) as soon as possible. When the spirit of OOP has the ability to control the overall situation, but the many small details of C + + is not very clear, is to return to the C + + object model of the time.

Growth is in the higher order (polymorphism) and lower (object model) between the shock, to be able to shock to a higher level, rather than flat mediocre in the middle (c + + syntax) of a pool of stagnant water.

Related Article

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.