safe and exceptionally secure code:Widget widget:: operator= (const WIDGETRHS){Bitmap *PORIG=PB;Pb=new Bitmap (*RHS.PB);Delete Porig;return *this;}At this point, if new Bitmao throws an exception, PB remains intact, and this code can handle self-assignment.Article 12: Do not forget every ingredient when copying an objectWhen you compose a copy function for a derived class, you must carefully assign its base class component. Those components are often private, so you can't access them directly,
Depending on C + + as a language federationThis section is effective C + +, the first section of the book, the content is the C + + language characteristics of the description, in fact, C + + features are diverse, it is different from the Java,java is a pure object-oriented
make water muddy, sometimes you may simply grab your compiler, "tell me what type of export you are pushing", and you can look at clause 4, because clause 4 is about how to persuade your compiler to do so.Please remember:
When the template parameter is a pointer or a reference, but not a universal reference (universal Reference), the instantiated expression is a reference that is ignored.
When the template parameter is a universal reference (universal Reference), the arg
Written in the previous words:1, from now, this moment, began to work hard, move up!2, "Effective OBJECTIVE-C 2.0" This is a very real book, each chapter with specific examples to inform readers of such reasons!3, the book has been bought for a long time, but also go out to see, this is in accordance with the book chapters, summed up the contents of the book and their own experience!4, willing to share the
Original Http://tutuge.me/2015/03/21/effective-objective-c-5-enum/?utm_source=tuicoolutm_medium=referral PrefaceEnums, which are enumerations, start with the C language, C + +, Java, objective-c, Swift, all of which have corresponding enumeration types, and may have less fun
Simple analysis summarizes the top 10 articles of more effective C + +:The rest of the terms to be continue~1. Carefully differentiate pointers and referencesThe reference must not point to NULL, the pointer can point to NULL, the pointer is initialized to remember to assign a null value,Overloading certain operations (for example []) should return a reference.2. It is best to use
Chapter Review:The 1th chapter of effective C + + makes himself accustomed to c++-reading notesEffective C + + 2nd structure/destructor/assignment operation (1)-Reading notesEffective C + + 2nd structure/destructor/assignment operation (2)-Reading notes"
When you throw an exception, you introduce an interrupt event in the application. And crisis to the control process of the program. So that the desired behavior cannot occur. What's worse, you have to leave the cleanup work to the programmer who has caught the exception with the final write code. And when an exception occurs, if you can capture it directly from the state of the program you are managing, then you can take some effective steps. Thankful
Next is the more effective C + + 11 to 20 section:11. Suppress exception information (exceptions) from being passed to the destructor.There are two possible types of destructors: (1) Normal destruction of objects (2) stack unwinding mechanism during abnormal propagation-destroy.If an exception is thrown within a destructor, it is not captured by the destructor, it propagates to the call side of the destruct
Yesterday bought a "effective C #", saw a few item, although not originally read "Effective C + +" when the shock, but also harvested a lot. Put the key points in the following, some provisions add their own understanding, the right as a reading note:-)
Item 1:always Use Properties Instead the Accessible Data members
problem, and there is a problem when the customer needs more than one return value to exist: if (( a * b ) == ( c * d //... } If operator* the return value is a static variable, then the above conditions determine the constant, because the equals sign is the same object on both sides. If you think about using an array of static variables to store the return value, then I can't spit out the slot ...Struggling with this many, let's return
{... Templateclass demo{...} ... Templatevoid swap (demo RHS) { Lhs.swap (RHS); }}View CodeOf course, the above can also be declared within the global namespace, but this may cause a messy scope (in the effective C + + Chinese version, to maintain "decent and moderate").3. Assume for the following functions:Templatevoid dosomething{t lhs,t rhs) { ... Swap (LHS,RHS); ...}View Cod
error may be the place will be wrong. There is no problem with the argument, but the function at run time treats the incoming array name in the form of type B, thus causing danger. So polymorphic can really not be used on the array? I think it is possible to use an array of pointers instead of directly using an object (an instance of Class). I think this clause is primarily for object arrays.
It is not necessary to provide default constructor. The default constructor refers to the constructor
0Guideabbreviation: constructor ctor destructor Dtor1Make yourself accustomed to C + +C+ + times Language: C, object_oriented C + +, Template C + +, STL with const,enum, inline replace#define ConstThe member function commits to never change the logical state of its object
the two class implementations are not negligible. If you should start with your reality, consider using these techniques in an asymptotic way.Summarize:1) The general idea of supporting the minimization of compile dependencies is that it depends on the declarative, not on the definition. The two instruments based on this conception are handle classes and interface classes.2) The library header file should be in the form of "complete and only declarative" (Full and Declaration-only forms). This
columns (ITEM13), including, but not limited to, smart pointers in TR1. One such non-TR1 smart pointer is Scoped_array, a smart pointer, like AUTO_PTR, provided for dynamically allocated arrays; Item44 provides an instance.
Miscellaneous, including libraries for CRC Checksum, a library of date and time operations, and libraries to move on file systems.
Remember, this is only part of the program library in boost. Not all of them are listed.The boost provides a library that can do a lot
corresponding copy function in all parent classes.
You may have noticed the repetition of the code, but don't let the copy constructor and the assignment operator call each other, their semantics are completely different! C + + does not even provide a syntax for the assignment operator to invoke the copy constructor, which in turn allows the copy constructor call assignment operator to compile, but because the precondition of the copy construct
As a result of the recent entry, the company arranged to study freely, so there is time to effective OBJECTIVE-C 2.0 a book to study again. As a result of the narrow personal knowledge, some of the contents of the book can not be understood thoroughly, now will be learned to do the understanding of the content to do a comb, the personal think of common and important knowledge recorded, for future reference.
"Effective C + +" Chapter Nineth: Miscellaneous Discussion
Do not neglect the compiler's warnings. Take a warning message from the compiler seriously. Strive for no warning at the highest warning level. Also do not rely too much on the compiler to give the warning message, different compiler gives the warning message is not the same, even give the warning point is not the same.
Familiarize yourself
Today began to see effective C + +, feel good writing, hereby in their own language record a deeper impression ~1. Learn what functions the C + + compiler will write and call by defaultWhen declaring an empty class, the compiler silently writes 4 functions for the class and calls them to implement the function of the class a{};//with the support of the compiler,
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.