<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…
Object Oriented Design is the concept that forces programmers to plan out their code in order to have a better flowing program. The origins of object oriented design is debated, but the first languages that supported it included Simula and SmallTalk.…
<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 9> Never call virtual functions during construction or destruction 1.you shouldn't call virtual functions during construction or destruction, because the calls won't do what you think, and if they did, you'd still be unhappy. If you're a recov…
<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…
<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…