亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? ei36.htm

?? 一個非常適合初學者入門的有關c++的文檔
?? HTM
?? 第 1 頁 / 共 2 頁
字號:
 Effective C++, 2E | Item 36: Differentiate between inheritance of interface and inheritance of implementation Back to Item 35: Make sure public inheritance models "isa."Continue to Item 37: Never redefine an inherited nonvirtual function.Item 36: Differentiate between inheritance of interface and inheritance of implementation.The seemingly straightforward notion of (public) inheritance turns out, upon closer examination, to be composed of two separable parts: inheritance of function interfaces and inheritance of function implementations. The difference between these two kinds of inheritance corresponds exactly to the difference between function declarations and function definitions discussed in the Introduction to this book.As a class designer, you sometimes want derived classes to inherit only the interface (declaration) of a member function; sometimes you want derived classes to inherit both the interface and the implementation for a function, but you want to allow them to override the implementation you provide; and sometimes you want them to inherit both interface and implementation without allowing them to override anything.To get a better feel for the differences among these options, consider a class hierarchy for representing geometric shapes in a graphics application: class Shape {public:  virtual void draw() const = 0;  virtual void error(const string& msg);  int objectID() const;  ...};class Rectangle: public Shape { ... };class Ellipse: public Shape { ... };Shape is an abstract class; its pure virtual function draw marks it as such. As a result, clients cannot create instances of the Shape class, only of the classes derived from it. Nonetheless, Shape exerts a strong influence on all classes that (publicly) inherit from it, becauseMember function interfaces are always inherited. As explained in Item 35, public inheritance means isa, so anything that is true of a base class must also be true of its derived classes. Hence, if a function applies to a class, it must also apply to its subclasses.Three functions are declared in the Shape class. The first, draw, draws the current object on an implicit display. The second, error, is called by member functions if they need to report an error. The third, objectID, returns a unique integer identifier for the current object; Item 17 gives an example of how such a function might be used. Each function is declared in a different way: draw is a pure virtual function; error is a simple (impure?) virtual function; and objectID is a nonvirtual function. What are the implications of these different declarations?Consider first the pure virtual function draw. The two most salient features of pure virtual functions are that they must be redeclared by any concrete class that inherits them, and they typically have no definition in abstract classes. Put these two traits together, and you realize thatThe purpose of declaring a pure virtual function is to have derived classes inherit a function interface only.This makes perfect sense for the Shape::draw function, because it is a reasonable demand that all Shape objects must be drawable, but the Shape class can provide no reasonable default implementation for that function. The algorithm for drawing an ellipse is very different from the algorithm for drawing a rectangle, for example. A good way to interpret the declaration of Shape::draw is as saying to designers of subclasses, "You must provide a draw function, but I have no idea how you're going to implement it."Incidentally, it is possible to provide a definition for a pure virtual function. That is, you could provide an implementation for Shape::draw, and C++ wouldn't complain, but the only way to call it would be to fully specify the call with the class name: Shape *ps = new Shape;           // error! Shape is abstractShape *ps1 = new Rectangle;      // fineps1->draw();                     // calls Rectangle::drawShape *ps2 = new Ellipse;        // fineps2->draw();                     // calls Ellipse::drawps1->Shape::draw();              // calls Shape::drawps2->Shape::draw();              // calls Shape::drawAside from helping impress fellow programmers at cocktail parties, knowledge of this feature is generally of limited utility. As you'll see below, however, it can be employed as a mechanism for providing a safer-than-usual default implementation for simple (impure) virtual functions.Sometimes it's useful to declare a class containing nothing but pure virtual functions. Such a Protocol class can provide only function interfaces for derived classes, never implementations. Protocol classes are described in Item 34 and are mentioned again in Item 43.The story behind simple virtual functions is a bit different from that behind pure virtuals. As usual, derived classes inherit the interface of the function, but simple virtual functions traditionally provide an implementation that derived classes may or may not choose to override. If you think about this for a minute, you'll realize thatThe purpose of declaring a simple virtual function is to have derived classes inherit a function interface as well as a default implementation.In the case of Shape::error, the interface says that every class must support a function to be called when an error is encountered, but each class is free to handle errors in whatever way it sees fit. If a class doesn't want to do anything special, it can just fall back on the default error-handling provided in the Shape class. That is, the declaration of Shape::error says to designers of subclasses, "You've got to support an error function, but if you don't want to write your own, you can fall back on the default version in the Shape class."It turns out that it can be dangerous to allow simple virtual functions to specify both a function declaration and a default implementation. To see why, consider a hierarchy of airplanes for XYZ Airlines. XYZ has only two kinds of planes, the Model A and the Model B, and both are flown in exactly the same way. Hence, XYZ designs the following hierarchy: class Airport { ... };      // represents airportsclass Airplane {public:  virtual void fly(const Airport& destination);  ...};void Airplane::fly(const Airport& destination){  default code for flying an airplane to  the given destination}class ModelA: public Airplane { ... };class ModelB: public Airplane { ... };To express that all planes have to support a fly function, and in recognition of the fact that different models of plane could, in principle, require different implementations for fly, Airplane::fly is declared virtual. However, in order to avoid writing identical code in the ModelA and ModelB classes, the default flying behavior is provided as the body of Airplane::fly, which both ModelA and ModelB inherit.This is a classic object-oriented design. Two classes share a common feature (the way they implement fly), so the common feature is moved into a base class, and the feature is inherited by the two classes. This design makes common features explicit, avoids code duplication, facilitates future enhancements, and eases long-term maintenance all the things for which object-oriented technology is so highly touted. XYZ Airlines should be proud.Now suppose that XYZ, its fortunes on the rise, decides to acquire a new type of airplane, the Model C. The Model C differs from the Model A and the Model B. In particular, it is flown differently.XYZ's programmers add the class for Model C to the hierarchy, but in their haste to get the new model into service, they forget to redefine the fly function: class ModelC: public Airplane {  ...                          // no fly function is                               // declared};In their code, then, they have something akin to the following: Airport JFK(...);              // JFK is an airport in                               // New York CityAirplane *pa = new ModelC;...pa->fly(JFK);                  // calls Airplane::fly!This is a disaster: an attempt is being made to fly a ModelC object as if it were a ModelA or a ModelB. That's not the kind of behavior that inspires confidence in the traveling public.The problem here is not that Airplane::fly has default behavior, but that ModelC was allowed to inherit that behavior without explicitly saying that it wanted to. Fortunately, it's easy to offer default behavior to subclasses, but not give it to them unless they ask for it. The trick is to sever the connection between the interface of the virtual function and its default implementation. Here's one way to do it: class Airplane {public:  virtual void fly(const Airport& destination) = 0;  ...protected:  void defaultFly(const Airport& destination);};void Airplane::defaultFly(const Airport& destination){

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美精品一区二区三区久久久| 亚洲人成在线观看一区二区| 中文乱码免费一区二区| 亚洲永久免费视频| 极品销魂美女一区二区三区| 99re这里只有精品视频首页| 日韩欧美色综合| 一区二区三区四区亚洲| 国产白丝精品91爽爽久久| 欧美日本不卡视频| 亚洲男人的天堂网| 国产精品亚洲第一| 91精品国产综合久久蜜臀| 亚洲三级电影全部在线观看高清| 国产综合久久久久久鬼色| 欧美午夜一区二区三区| 国产精品青草久久| 99麻豆久久久国产精品免费| 日韩一区二区在线观看| 亚洲一区二区三区在线看| 成人国产精品免费观看| 国产视频一区不卡| 国产一区欧美日韩| 精品国产免费一区二区三区香蕉| 日韩极品在线观看| 欧美视频一二三区| 一区二区三区资源| 色呦呦国产精品| 自拍av一区二区三区| 成人av一区二区三区| 欧美激情中文字幕一区二区| 国产一区二区三区| 久久久精品黄色| 国产一区二区三区四| 久久久久久久一区| 国产一区二区伦理片| 久久中文字幕电影| 国产一区二区免费在线| 久久综合给合久久狠狠狠97色69| 精品一区二区在线观看| 日韩一级片网站| 久久精品国产亚洲aⅴ| 精品美女被调教视频大全网站| 免费高清在线一区| 欧美精品一区二| 国产精品亚洲综合一区在线观看| 久久久精品免费网站| 成人精品小蝌蚪| 亚洲一区二区精品3399| 欧美日韩国产高清一区| 激情综合网天天干| 国产精品电影院| 日本久久精品电影| 日韩成人免费看| 精品少妇一区二区三区在线视频| 狠狠色狠狠色综合| 国产精品女主播在线观看| 色欧美乱欧美15图片| 亚洲成av人片www| 日韩欧美精品在线视频| 国产福利91精品一区| 一区二区三区中文字幕| 欧美大片在线观看一区二区| 成人精品国产福利| 亚洲不卡av一区二区三区| 精品国产一二三区| 色系网站成人免费| 久久99热这里只有精品| 综合久久给合久久狠狠狠97色| 欧美丝袜丝nylons| 国产精品99久久久久久久女警| 亚洲免费av在线| 26uuu亚洲| 欧美日韩视频一区二区| 国产高清不卡二三区| 亚洲国产日韩a在线播放| 26uuu国产日韩综合| 91精品1区2区| 国产精品羞羞答答xxdd| 一区二区在线观看免费视频播放| 欧美日韩dvd在线观看| 九九在线精品视频| 欧美不卡视频一区| 北条麻妃一区二区三区| 亚洲网友自拍偷拍| 欧美成人国产一区二区| eeuss鲁一区二区三区| 亚洲国产精品视频| 91国在线观看| 成人一级视频在线观看| 亚洲综合色噜噜狠狠| 精品成人私密视频| 91官网在线免费观看| 精品在线视频一区| 亚洲激情av在线| 久久免费美女视频| 欧美性感一类影片在线播放| 国内精品在线播放| 一区二区三区不卡视频| 久久精品一区二区三区不卡| 91.xcao| 国产a区久久久| 日本欧美一区二区三区| 自拍av一区二区三区| 国产日韩欧美高清| 在线成人免费视频| 99久久久免费精品国产一区二区| 日本欧美一区二区| 亚洲午夜久久久| 亚洲色图制服丝袜| 国产日韩欧美在线一区| 久久久久久久久一| 日韩欧美精品在线视频| 欧美三日本三级三级在线播放| 成人三级伦理片| 国产激情视频一区二区三区欧美| 日本aⅴ精品一区二区三区 | 色88888久久久久久影院按摩| 蜜臀av性久久久久蜜臀aⅴ| 亚洲欧美另类综合偷拍| 久久久99精品免费观看不卡| 欧美日韩久久不卡| 欧美日韩精品一区视频| 一本高清dvd不卡在线观看 | 欧美日韩aaaaaa| 欧美日韩视频一区二区| 日本乱人伦一区| 欧美高清视频一二三区 | 日韩一区二区三区在线| 91免费版在线| 91丨九色丨蝌蚪富婆spa| 国产成人av电影| 国模娜娜一区二区三区| 亚洲成a人v欧美综合天堂下载| 污片在线观看一区二区| 午夜久久久久久| 日韩av中文在线观看| 麻豆精品在线看| 蜜臀av国产精品久久久久| 日韩国产在线观看一区| 亚洲成人www| 一区二区三区 在线观看视频| 午夜欧美在线一二页| 日本不卡视频在线| 精久久久久久久久久久| 精品一区二区在线视频| 激情六月婷婷综合| 成人激情免费视频| 色一情一伦一子一伦一区| 欧美一区午夜精品| 日韩三级视频在线观看| 中文字幕的久久| 日韩精彩视频在线观看| 国产一区二三区好的| 99久精品国产| 欧美美女一区二区| 欧美激情中文不卡| 亚洲一区二区影院| 成人久久久精品乱码一区二区三区| 色视频成人在线观看免| 久久综合久色欧美综合狠狠| 国产精品盗摄一区二区三区| 天天色天天操综合| 国产一区二区三区电影在线观看| 成人av动漫网站| 欧美另类久久久品| 久久精品一区四区| **欧美大码日韩| 亚洲超碰精品一区二区| 国产乱码字幕精品高清av| 91色综合久久久久婷婷| 日韩欧美久久久| 中文字幕亚洲一区二区va在线| 亚洲欧美色一区| 韩国av一区二区| 欧美三级三级三级爽爽爽| 久久综合色天天久久综合图片| 性久久久久久久久久久久| 国产在线视频一区二区| 欧美四级电影在线观看| 久久综合色播五月| 天天色 色综合| 国产在线视频一区二区| 欧美大度的电影原声| 亚洲女子a中天字幕| 国产91精品免费| 717成人午夜免费福利电影| 日韩欧美自拍偷拍| 亚洲图片你懂的| 粉嫩绯色av一区二区在线观看| 欧美日韩欧美一区二区| 中文字幕一区二区三区四区不卡 | 国产三级一区二区三区| 亚洲一区二区欧美| 国产成人精品免费网站| 欧美一区二区三区啪啪| 亚洲影院免费观看| 97精品超碰一区二区三区| 国产欧美精品国产国产专区| 国产乱码字幕精品高清av|