Accelerated C++的笔记(31)
按有用程度 按页码先后 最新笔记
-
15.1
Universe (Hello, world.)
这一张讲的是设计,有人对我说过,写代码不值钱,设计才值钱。不过值钱的东西往往不容易理解,像这章就是。将现实问题分解,然后再重新构成软件,本身就是一个费脑筋的过程。要把这个过程给不了解的人讲清楚,就更费脑筋了。这一章的讲解只能说合格,没有前面的章节那么容易理解。 15.1.1 Using inheritance to model the structure We'll call the derived classes String_Pic, for pictures created from strings that our u... (更多)2011-07-31 09:07:20 回应
-
15.2
Universe (Hello, world.)
15.2.3 Padding the output Static members (both functions and static data members, which we can also define) are useful in that they let us minimize the names that are defined globally. Our pad function is a good example. We can imagine many abstractions that have the notion of padding. In this book we talked about padding in the context of writing a formatted report of student grades, as well a... (更多)2011-07-29 17:21:50 回应
-
14.4
Universe (Hello, world.)
14.4.1 Copying types that we can't control Solutions to tough problems such as this one often involve what we jokingly call the fundamental theorem of software engineering: All problems can be solved by introducing an extra level of indirection. The problem is that we are trying to call a member function that does not exist, and we have no way to cause the member function to exist. The solution... (更多)2011-07-28 08:38:31 回应
-
14.2
Universe (Hello, world.)
14.2 Reference-counted handles We have added a second data member to our Ref_handle class, and updated the constructors to initialize that new member. The default constructor and the constructor that takes a T* create new Ref_handle objects, so they allocate a new reference count (of type size_t) and set the value of that counter to 1. The copy constructor doesn't create a new object. Instead, ... (更多)2011-07-19 11:50:38 回应
-
14.1
Universe (Hello, world.)
14.1.1 A generic handle class The -> operator is a bit more complicated. Superficially, -> looks like a binary operator, but in fact it behaves differently from ordinary binary operators. Like the scope or dot operators, the -> operator is used to access a member whose name appears in its right operand from an object named by its left operand. Because names are not expressions, we have... (更多)2011-07-18 22:26:57 回应
-
13.6
Universe (Hello, world.)
13.6.1 Inheritance and containers What may be more surprising is what would happen if we persisted in defining a vector<Core> into which we intended to place either Core objects or Grad objects. The answer is that we could do so, but the results would probably be a surprise; for example /代码内容已省略/ We are allowed to store the Grad object in students... (更多)2011-07-17 12:17:21 回应
-
13.2
Universe (Hello, world.)
13.2.1 Obtaining a value without knowing the object's type The virtual keyword may be used only inside the class definition. If the functions are defined separately from their declarations, we do not repeat virtual in the definitions. Thus, the definition of Core::grade() need not change. Similarly, the fact that a function is virtual is inherited, so we need not repeat the virtual designation on... (更多)2011-07-14 16:11:20 回应
-
12.3
Universe (Hello, world.)
/代码内容已省略/ The index operators just forward their work to the corresponding Vec operations. It is worth noting that, as we did for class Vec, we define two versions of the index operator—one that can operate on const objects and the other that cannot. By returning a reference to the character, the nonconst version gives write access to the character that ... (更多)2011-07-09 21:34:49 回应





