09 2021 档案

摘要:Virtual functions are dynamically bound, but default parameter values are statically bound. An object’s static type is the type you declare it to have 阅读全文
posted @ 2021-09-29 09:34 MyCPlusPlus 阅读(114) 评论(0) 推荐(0)
摘要:Consider: class B { public: void mf(); // ... }; class D : public B { /*...*/ }; D x; // x is an object of type D B *pB = &x; // get pointer to x pB-> 阅读全文
posted @ 2021-09-28 20:49 MyCPlusPlus 阅读(56) 评论(0) 推荐(0)
摘要:The Template Method Pattern via the Non-Virtual Interface Idiom: class GameCharacter { public: int healthValue() const // derived classes do not redef 阅读全文
posted @ 2021-09-28 20:34 MyCPlusPlus 阅读(204) 评论(0) 推荐(0)
摘要:The seemingly straightforward notion of (public) inheritance turns out, upon closer examination, to be composed of two separable parts: inheritance of 阅读全文
posted @ 2021-09-28 11:35 MyCPlusPlus 阅读(74) 评论(0) 推荐(0)
摘要:C++'s name-hiding rules do just that: hide names. Whether the names correspond to the same or different types is immaterial. int x; // global variable 阅读全文
posted @ 2021-09-14 10:38 MyCPlusPlus 阅读(128) 评论(0) 推荐(0)
摘要:Consider this code: class Rectangle { public: virtual void setHeight(int newHeight); virtual void setWidth(int newWidth); virtual int height() const; 阅读全文
posted @ 2021-09-13 10:50 MyCPlusPlus 阅读(54) 评论(0) 推荐(0)
摘要:C++ doesn't do a very good job of separating interfaces from implementations. A class definition specifies not only a class interface but also a fair 阅读全文
posted @ 2021-09-10 18:09 MyCPlusPlus 阅读(121) 评论(0) 推荐(0)
摘要:When you inline a function, you may enable compilers to perform context-specific optimizations on the body of the function. Most compilers never perfo 阅读全文
posted @ 2021-09-10 14:32 MyCPlusPlus 阅读(137) 评论(0) 推荐(0)
摘要:Suppose we have a class for representing GUI menus with background images. The class is designed to be used in a threaded environment, so it has a mut 阅读全文
posted @ 2021-09-10 11:12 MyCPlusPlus 阅读(108) 评论(0) 推荐(0)
摘要:Suppose you’re working on an application involving rectangles. Each rectangle can be represented by its upper left corner and its lower right corner. 阅读全文
posted @ 2021-09-09 19:57 MyCPlusPlus 阅读(84) 评论(0) 推荐(0)
摘要:Let’s begin with a review of casting syntax, because there are usually three different ways to write the same cast. C-style casts look like this: (T) 阅读全文
posted @ 2021-09-09 18:00 MyCPlusPlus 阅读(75) 评论(0) 推荐(0)
摘要:This suggests the real meaning of "as long as possible" in this Item’s title. Not only should you postpone a variable's definition until right before 阅读全文
posted @ 2021-09-09 16:58 MyCPlusPlus 阅读(105) 评论(0) 推荐(0)
摘要:To swap the values of two objects is to give each the other's value. By default, swapping is accomplished via the standard swap algorithm. Its typical 阅读全文
posted @ 2021-09-09 16:13 MyCPlusPlus 阅读(88) 评论(0) 推荐(0)
摘要:You might start your Rational class this way: class Rational { public: Rational(int numerator = 0, // ctor is deliberately not explicit; int denominat 阅读全文
posted @ 2021-09-07 18:25 MyCPlusPlus 阅读(109) 评论(0) 推荐(0)
摘要:Imagine a class for representing web browsers. Among the many functions such a class might offer are those to clear the cache of downloaded elements, 阅读全文
posted @ 2021-09-07 17:33 MyCPlusPlus 阅读(149) 评论(0) 推荐(0)
摘要:If everything in the public interface is a function, clients won't have to scratch their heads trying to remember whether to use parentheses when they 阅读全文
posted @ 2021-09-07 17:02 MyCPlusPlus 阅读(54) 评论(0) 推荐(0)
摘要:Consider a class for representing rational numbers, including a function for multiplying two rationals together: class Rational { public: Rational(int 阅读全文
posted @ 2021-09-07 16:35 MyCPlusPlus 阅读(98) 评论(0) 推荐(0)
摘要:By default, C++ passes objects to and from functions by value (a characteristic it inherits from C).The end result is that passing an object by value 阅读全文
posted @ 2021-09-07 15:42 MyCPlusPlus 阅读(146) 评论(0) 推荐(0)
摘要:How do you design effective classes? First, you must understand the issues you face. Virtually every class requires that you confront the following qu 阅读全文
posted @ 2021-09-07 11:18 MyCPlusPlus 阅读(83) 评论(0) 推荐(0)
摘要:Developing interfaces that are easy to use correctly and hard to use incorrectly requires that you consider the kinds of mistakes that clients might m 阅读全文
posted @ 2021-09-07 10:50 MyCPlusPlus 阅读(69) 评论(0) 推荐(0)
摘要:Suppose we have a function to reveal our processing priority and a second function to do some processing on a dynamically allocated Widget in accord w 阅读全文
posted @ 2021-09-03 09:37 MyCPlusPlus 阅读(46) 评论(0) 推荐(0)
摘要:When you employ a new expression (i.e., dynamic creation of an object via a use of new), two things happen. First, memory is allocated (via a function 阅读全文
posted @ 2021-09-03 09:25 MyCPlusPlus 阅读(57) 评论(0) 推荐(0)
摘要:,Item 13 introduces the idea of using smart pointers like auto_ptr or tr1::shared_ptr to hold the result of a call to a factory function like createIn 阅读全文
posted @ 2021-09-02 19:40 MyCPlusPlus 阅读(74) 评论(0) 推荐(0)
摘要:For example, suppose you’re using a C API to manipulate mutex objects of type Mutex offering functions lock and unlock: void lock(Mutex *pm); // lock 阅读全文
posted @ 2021-09-02 17:38 MyCPlusPlus 阅读(48) 评论(0) 推荐(0)
摘要:Consider this code: class Investment { /*...*/ }; // root class of hierarchy of investment types Investment* createInvestment(); // return ptr to dyna 阅读全文
posted @ 2021-09-01 17:13 MyCPlusPlus 阅读(41) 评论(0) 推荐(0)