亚洲欧美第一页_禁久久精品乱码_粉嫩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一区二区三区免费野_久草精品视频
国产精品久久久久久亚洲毛片 | 欧美中文字幕一区二区三区| 国产精品福利影院| 国产91丝袜在线播放九色| 精品久久人人做人人爽| 国产一区二区三区四区五区美女| 欧美精品一区二区久久婷婷| 国产一区二区精品久久| 国产精品久久久久久户外露出| av男人天堂一区| 一区二区三区影院| 69堂亚洲精品首页| 国产精品18久久久久久vr| 国产精品高清亚洲| 欧美日本高清视频在线观看| 狠狠网亚洲精品| 亚洲欧美二区三区| 日韩亚洲欧美在线| 丁香婷婷综合网| 亚洲国产另类av| 国产亚洲欧洲997久久综合| 91亚洲精品一区二区乱码| 亚洲一区二区美女| 久久综合久久综合亚洲| 日本久久一区二区| 精品在线播放午夜| 亚洲欧美在线视频| 日韩美女视频一区二区在线观看| 欧美视频三区在线播放| 久色婷婷小香蕉久久| 亚洲少妇中出一区| 精品女同一区二区| 色婷婷综合久久久久中文| 久久精品久久综合| 伊人色综合久久天天| 欧美精品一区二区三区高清aⅴ | 国产成人综合网| 亚洲午夜日本在线观看| 国产午夜精品久久| 91精品国产全国免费观看| 成人国产免费视频| 麻豆成人av在线| 亚洲自拍偷拍九九九| 欧美国产综合色视频| 欧美丰满一区二区免费视频 | 久久美女高清视频| 欧美亚洲精品一区| 成人性生交大合| 免费成人美女在线观看| 亚洲欧美一区二区三区孕妇| 久久色.com| 欧美一二三四在线| 欧美亚洲一区二区在线| 99re在线视频这里只有精品| 国产一区二区三区在线看麻豆| 午夜精品久久久久久久| 亚洲免费高清视频在线| 国产精品午夜在线观看| 久久亚洲精品小早川怜子| 日韩欧美一区二区在线视频| 欧美日韩国产免费一区二区| 色婷婷久久一区二区三区麻豆| 成人深夜在线观看| 国产91精品精华液一区二区三区| av中文字幕一区| 国产精品一区二区黑丝| 久久99精品久久久久婷婷| 人人超碰91尤物精品国产| 亚洲高清视频中文字幕| 亚洲一区在线观看免费观看电影高清 | 日本视频在线一区| 亚洲h精品动漫在线观看| 亚洲大尺度视频在线观看| 亚洲一级片在线观看| 亚洲第一综合色| 一二三四社区欧美黄| 亚洲色图在线视频| 亚洲制服欧美中文字幕中文字幕| 亚洲欧美另类图片小说| 一区二区欧美国产| 亚洲综合无码一区二区| 亚洲成av人片一区二区| 日本不卡高清视频| 老司机午夜精品| 国产一区视频网站| 成人不卡免费av| 91久久久免费一区二区| 欧美天天综合网| 欧美精品vⅰdeose4hd| 欧美一区欧美二区| 久久亚洲一区二区三区明星换脸 | 日韩精品一区二区三区视频播放 | 亚洲欧美偷拍卡通变态| 亚洲激情在线激情| 婷婷综合五月天| 麻豆一区二区在线| 国产成人av资源| 一本色道久久综合亚洲aⅴ蜜桃| 91高清视频免费看| 日韩视频在线观看一区二区| 久久久久99精品国产片| 亚洲女同女同女同女同女同69| 午夜精品在线看| 国产精品99久久久久久似苏梦涵 | 一区二区三区日韩精品视频| 午夜精品久久久久影视| 国产麻豆精品在线观看| 色呦呦日韩精品| 欧美一区二区三区爱爱| 国产精品丝袜一区| 亚洲一区免费观看| 九九九精品视频| 91麻豆成人久久精品二区三区| 欧美日韩一区二区三区在线看 | 成年人网站91| 7777精品伊人久久久大香线蕉最新版| 337p日本欧洲亚洲大胆色噜噜| 亚洲日本乱码在线观看| 久久99精品久久久久久国产越南 | 欧美乱妇15p| 久久精品一区四区| 亚洲aⅴ怡春院| 高清视频一区二区| 欧美高清激情brazzers| 日韩av在线发布| 国产精品久久久久久久久久久免费看 | 国内精品视频一区二区三区八戒| 92精品国产成人观看免费| 成人18视频日本| 国产精品久久久久一区 | 91日韩一区二区三区| 欧美国产欧美亚州国产日韩mv天天看完整 | 欧美日韩激情一区| 亚洲综合999| 欧美视频你懂的| 午夜视频在线观看一区二区| 欧美日韩视频专区在线播放| 亚洲成人777| 欧美精品aⅴ在线视频| 婷婷激情综合网| 欧美精品在线一区二区三区| 日韩电影在线看| 精品少妇一区二区三区| 国内精品久久久久影院薰衣草| 久久日韩精品一区二区五区| 国产麻豆一精品一av一免费| 国产清纯美女被跳蛋高潮一区二区久久w| 国产一本一道久久香蕉| 欧美韩国一区二区| 9人人澡人人爽人人精品| 亚洲欧美日韩国产综合| 欧洲日韩一区二区三区| 午夜久久久久久电影| 制服丝袜中文字幕一区| 国产一区二区主播在线| 一区在线中文字幕| 欧美在线三级电影| 免费欧美高清视频| 欧美精品一区二区三区四区 | 99免费精品在线| 亚洲国产成人porn| 欧美一区二区在线播放| 狠狠v欧美v日韩v亚洲ⅴ| 中文字幕av一区二区三区| 在线观看欧美黄色| 久久精品999| 中文字幕一区二区三区色视频| 欧美在线高清视频| 免费人成精品欧美精品 | 亚洲一二三四区不卡| 欧美成人video| 91在线小视频| 久久精品噜噜噜成人av农村| 国产精品乱码人人做人人爱| 欧美视频一区二区在线观看| 国产乱子轮精品视频| 亚洲精品国产视频| 亚洲精品在线一区二区| 色哟哟一区二区在线观看| 美女一区二区视频| 亚洲人亚洲人成电影网站色| 777a∨成人精品桃花网| av电影在线不卡| 韩国三级电影一区二区| 亚洲国产日韩一级| 国产午夜精品福利| 337p亚洲精品色噜噜狠狠| jizzjizzjizz欧美| 黄色成人免费在线| 亚洲成人中文在线| 国产精品福利电影一区二区三区四区| 91麻豆精品91久久久久同性| www.色精品| 国产一区二区三区精品欧美日韩一区二区三区 | 国产精品麻豆视频| 91精品在线一区二区| 91欧美一区二区| 国产精品一区免费视频| 三级不卡在线观看| 亚洲欧美日韩综合aⅴ视频|