freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

面向?qū)ο蟪绦虍厴I(yè)設計中英文對照文檔-在線瀏覽

2025-01-04 19:54本頁面
  

【正文】 okstore example, we will define a base class, which we39。ll name Bulk_item, to represent books sold with a quantity discount. At a minimum, these classes will define the following operations: ? an operation named book that will return the ISBN ? an operation named _price that returns the price for purchasing a specified number of copies of a book Classes derived from Item_base will inherit the book function without change: The derived classes have no need to redefine what it means to fetch the ISBN. On the other hand, each derived class will need to define its own version of the _price function to implement an appropriate discount pricing strategy. In C++, a base class must indicate which of its functions it intends for its derived classes to redefine. Functions defined as virtual are ones that the base expects its derived classes to redefine. Functions that the base class intends its children to inherit are not defined as virtual. Given this discussion, we can see that our classes will define three (const) member functions: ? A nonvirtual function, std::string book(), that returns the ISBN. It will be defined by Item_base and inherited by Bulk_item. ? Two versions of the virtual function, double _price(size_t), to return the total price for a given number of copies of a specific book. Both Item_base and Bulk_item will define their own versions of this function. Dynamic Binding Dynamic binding lets us write programs that use objects of any type in an inheritance hierarchy without caring about the objects39。os, const Item_base amp。 } The function39。book = , double sales_price = ): isbn(book), price(sales_price) { } std::string book() const { return isbn。 } virtual ~Item_base() { } private: std::string isbn。 // normal, undiscounted price }。ll explain virtual destructors in Section (p. 587), but for now it is worth noting that classes used as the root class of an inheritance hierarchy generally define a virtual destructor. BaseClass Member Functions The Item_base class defines two functions, one of which is preceded by the keyword virtual. The purpose of the virtual keyword is to enable dynamic binding. By default, member functions are nonvirtual. Calls to nonvirtual functions are resolved at pile time. To specify that a function is virtual, we precede its return type by the keyword virtual. Any nonstatic member function, other than a constructor, may be virtual. The virtual keyword appears only on the memberfunction declaration inside the class. The virtual keyword may not be used on a function definition that appears outside the class body. Access Control and Inheritance In a base class, the public and private labels have their ordinary meanings: User code may access the public members and may not access the private members of the class. The private members are accessible only to the members and friends of the base class. A derived class has the same access as any other part of the program to the public and private members of its base class: It may access the public members and has no access to the private members. Sometimes a class used as a base class has members that it wants to allow its derived classes to access, while still prohibiting access to those same members by other users. The protected access label is used for such members. A protected member may be accessed by a derived object but may not be accessed by general users of the type. Our Item_base class expects its derived classes to redefine the _price function. To do so, those classes will need access to the price member. Derived classes are expected to access isbn in the same way as ordinary users: through the book access function. Hence, the isbn member is private and is inaccessible to classes that inherit from Item_base. protected Members The protected access label can be thought of as a blend of private and public: ? Like private members, protected members are inaccessible to users of the class. ? Like public members, the protected members are accessible to classes derived from this class. In addition, protected has another important property: A derived object may access the protected members of its base class only through a derived object. The derived class has no special access to the protected members of base type objects. As an example, let39。d, const Item_base amp。 // ok: uses thisprice ret = 。 // error: no access to price from an Item_base } The use of is okay, because the reference to price is through an object of type Bulk_item. The use of is illegal because Bulk_item has no special access to objects of type Item_base. Derived Classes To define a derived class, we use a class derivation list to specify the base class(es). A class derivation list names one or more base classes and has the form class classname: accesslabel baseclass where accesslabel is one of public, protected, or private, and baseclass is the name of a previously defined class. As we39。ll have more to say about the access label used in a derivation list in Section (p. 570). For now, what39。 private: std::size_t min_qty。 // fractional discount to apply }。 derivation list. The base class itself specifies the minimal access control for its own members. If a member is private in the base class, then only the base class and its friends may access that member. The derived class has no access to the private members of its base class, nor can it make those members accessible to its own users. If a base class member is public or protected, then the access label used in the derivation list determines the access level of that member in the derived class: ? In public in
點擊復制文檔內(nèi)容
公司管理相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1