<Item29> Strive for exception-safe code. 1.如下面的代码 class PrettyMenu { public: ... void changeBackground(std::istream& imgSrc); // change background ... // image private: Mutex mutex; // mutex for this object Image *bgImage; // current background…
1.For the most part, coming up with appropriate definitions for your classes (and class templates) and appropriate declarations for your functions (and function templates) is the lion's share of the battle. Once you've got those right, the correspond…
<Item 18> Make interfaces easy to use correctly and hard to use incorrectly 1.That being the case, if they use one incorrectly, your interface is at least partially to blame. Ideally, if an attempted use of an interface won't do what the client expe…
<Item 1>View C++ as a federation of languages. 1.把C++看成4种子语言组成,即C.Object-Oriented C++.Template C++.The STL. 2.Things to Remember:Rules for effective C++ programming vary, depending on the part of C++ you are using. 因为C++有很多的编程范式,在项目开发过程中,明确规范怎么使用C++…
Introduction 1.Learning the fundamentals of a programming language is one thing; learning how to design and implement effective programs in that language is something else entirely. 想起<重构>里面说的一句话,写出计算机能理解的代码很容易,但是写好人能理解的代码不容易 2.A declaration tells c…
<Item 36> Never redefine an inherited non-virtual function 1.如下代码通过不同指针调用同一个对象的同一个函数会产生不同的行为The reason for this two-faced behavior is that non-virtual functions like B::mf and D::mf are statically bound (see Item 37). That means that because pB is d…
1.Furthermore, I explain what the different features in C++ really mean — what you are really expressing when you use a particular construct. For example, public inheritance means "is-a," and if you try to make it mean anything else, you'll run…
<Item 22> Declare data members private 1.使数据成员private,保持了语法的一致性,client不会为访问一个数据成员是否需要使用括号进行函数调度,还是不使用括号直接访问成员而纠结. 2.使数据成员private,if you use functions to get or set its value, you can implement no access, read-only access, and read-write access. Heck…
<Item 20> Prefer pass-by-reference-to-const to pass-by-value 1.By default, C++ passes objects to and from functions by value (a characteristic it inherits from C). Unless you specify otherwise, function parameters are initialized with copies of the…
<Item 5> Know what functions C++ silently writes and calls 1.If you don't declare them yourself, compilers will declare their own versions of a copy constructor, a copy assignment operator, and a destructor. Furthermore, if you declare no constructo…