Zephyr
1304
If you want to learn but not think about it, you can't think about it,
Recently, I have reviewed effectivec ++ and other books,
Discover many experiences,
We can learn new things in a gentle manner, and the Ancients will not bully me.
Also, designpattern, C ++ bottom layer, etc,
Before long-term use and large-scale system experience,
In the past, they used to be anchor's chanting,
For exampleInside C ++ objectWhat is said
"
Don't guess, don't wait for the master to solve it
"
To be advanced,
The spirit of extreme will be indispensable,
ProgramThe life cycle of each module is clear,
When were they born and when they left? What did they do?
This seems to be the simplest construction, destructor,
But I am ashamed to find that I am not very thorough,
By chance, it seems that some symbolic methods are very helpful for understanding,
For the sake of understanding, starting from the beginning,
Summary:
1If an object is equivalent to a person,
ThatConstructorIt is equivalent to his birth, the basic birth condition of a person (physiological condition,Component) Are the same,
Therefore, there can be multiple ConstructorsHeavy LoadBut the basic conditions are the same.Nothing(Data initialization, pointer settings)Null);
2. People are born and dead. When thinking of this, we don't have to worry about it. Instead, we should be open-minded, because no matter what we get on the long road of life, we finally have nothing to do, in particular, the Ministry of Civil Affairs will definitely cancel your account Account (the structure must clear all the data, especially the applicationHeap memoryAnd destroy the pointer settings.Null), Nothing can bring to heaven (orMemleak);
3. Even so, everyone is born with freedom and equality in time, but after all, the family and environment are different (there are differentConstructor), Is it inevitable that the rich and the poor are born, but there is a kind of friendship between the princes and the elders? Isn't all human beings determined at the moment of birth ?! (During Construction), no, there is still a chance of counterattack. Therefore, apart from the first point, allExternal ParametersWe should make the decision to construct attributes independently.ExtractIs a method, such as iniItems, inimoneyTo stay in the future;
4. It is impossible for a person to make his or her own birth. However, his or her grief is still heartless, and he or she can commit suicide. (Objects cannot be explicitly called. Constructor But can call Destructor ), And considering that sometimes it is not suicide, but may fall into the canyon and be reborn, we should also find a separate method for the destructor, such as cleanup. Money , Cleanupitems, Inimoney You may only need to raise the money (unless you have fallen from the handsome rich, clean into bankruptcy), but ini Items You may need to clear the original property (ini Items Cleanupitems first );
5. Just expand. The object pointer and the Object Data Pointer must be clearly separated. At first glance, it is very simple, but the reality is often confusing, after Gao Shuai Fu fell down, he had to charge n credit cards because of luxury and simplicity, and then went there.DeleteIsn't that scientific ?! There's a strawberry girl in front. Never give up! The data in the object cannot affect any operability of the Object Pointer;
6. If you are living in the world, you will inevitably encounter various people and things. There are also many unreliable things. "What is the most thrilling memory in your life ?" "Well, more than 20 years ago, I chased hundreds of millions of siblings and almost lost "... every time I live a bad life, I think about it all the time. I am stuck in such a difficult moment, and the various attribute methods, especially the variousNull,Wild pointerIs it duty-free ?!RobustnessRobust enough! During Construction and Analysis, various unexpected situations must be taken into account;
7. assign values directly during declaration to view the AssemblyCode, You will find that the copied constructor is called directly, rather than the overloaded " = " Operator. Copy Initialization And Value assignment Initialization , Expand, the value assignment initialization does not belong to the scope of the constructor, so the constructor cannot be compiled. Explicit call But we can do this in member functions, but we do not need to call it as well (for example, if an object has applied for a piece of memory before, when calling the constructor directly, the pointer will be directly set Null, but the applied memory is not released ). It can be a copy-initiated Constructor ( Just generate And then call the value assignment initialization ( Generated , Just generated object calls). This is a kind of focused attitude for people, focusing on their own business, the most clear scope of responsibility, for class, can avoid many problems.