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

正文內(nèi)容

面向?qū)ο蟪绦虍厴I(yè)設(shè)計(jì)中英文對(duì)照文檔-展示頁(yè)

2024-11-13 19:54本頁(yè)面
  

【正文】 a reference (or pointer) might refer to either a base or a derivedclass object is the key to dynamic binding. Calls to virtual functions made through a reference (or pointer) are resolved at run time: The function that is called is the one defined by the actual type of the object to which the reference (or pointer) refers. Defining Base and Derived Classes In many ways, base and derived classes are defined like other classes we have already seen. However, there are some additional features that are required when defining classes in an inheritance hierarchy. This section will present those features. Subsequent sections will see how use of these features impacts classes and the programs we write using inherited classes. Defining a Base Class Like any other class, a base class has data and function members that define its interface and implementation. In the case of our (very simplified) bookstore pricing application, our Item_base class defines the book and _price functions and needs to store an ISBN and the standard price for the book: // Item sold at an undiscounted price // derived classes will define various discount strategies class Item_base { public: Item_base(const std::string amp。item, size_t n) { os ISBN: () // calls Item_base::book \tnumber sold: n \ttotal price: // virtual call: which version of _price to call is resolved at run time (n) endl。 specific types. Programs that use these classes need not distinguish between functions defined in the base or in a derived class. For example, our bookstore application would let a customer select several books in a single sale. When the customer was done shopping, the application would calculate the total due. One part of figuring the final bill would be to print for each book purchased a line reporting the total quantity and sales price for that portion of the purchase. We might define a function named print_total to manage this part of the application. The print_total function, given an item and a count, should print the ISBN and the total price for purchasing the given number of copies of that particular book. The output of this function should look like: ISBN: 0201548488 number sold: 3 total price: 98 ISBN: 0201824701 number sold: 5 total price: Our print_total function might look something like the following: // calculate and print price for given number of copies, applying any discounts void print_total(ostream amp。ll name Item_base, to represent undiscounted books. From Item_base we will inherit a second class, which we39。ll look at the concepts that are fundamental to this style of programming. An Overview The key idea behind OOP is polymorphism. Polymorphism is derived from a Greek word meaning many forms. We speak of types related by inheritance as polymorphic types, because in many cases we can use the many forms of a derived or base type interchangeably. As we39。 二 ○ ○ 九 屆 畢 業(yè) 設(shè) 計(jì) 翻譯資料 學(xué) 院: 專 業(yè): 姓 名: 學(xué) 號(hào): 指導(dǎo)教師: 完成時(shí)間: 二〇〇九年三月 ObjectOriented Programming Objectoriented programming is based on three fundamental concepts: data abstraction, inheritance, and dynamic binding. In C++ we use classes for data abstraction and class derivation to inherit one class from another: A derived class inherits the members of its base class(es). Dynamic binding lets the piler determine at run time whether to use a function defined in the base or derived class. Inheritance and dynamic binding streamline our programs in two ways: They make it easier to define new classes that are similar, but not identical, to other classes, and they make it easier for us to write programs that can ignore the details of how those similar types differ.。 Many applications are characterized by concepts that are related but slightly different. For example, our bookstore might offer different pricing strategies for different books. Some books might be sold only at a given price. Others might be sold subject to some kind of discount strategy. We might give a discount to purchasers who buy a specified number of copies of the book. Or we might give a discount for only the first few copies purchased but charge full price for any bought beyond a given limit. Objectoriented programming (OOP) is a good match to this kind of application. Through inheritance we can define types that model the different kinds of books. Through dynamic binding we can write applications that use these types but that can ignore the typedependent differences. The ideas of inheritance and dynamic binding are conceptually simple but have profound implications for how we build our applications and for the features that programming languages must support. Before covering how C++ supports OOP, we39。ll see, in C++, polymorphism applies only to references or pointers to types related by inheritance. Inheritance Inheritance lets us define classes that model relationships among types, sharing what is mon and specializing only that which is inherently different. Members defined by the base class are inherited by its derived classes. The derived class can use, without change, those operations that do not depend on the specifics of the derived type. It can redefine those member functions that do depend on its type, specializing the function to take into account the peculiarities of the derived type. Finally, a derived class may define additional members beyond those it inherits from its base class. Classes related by inheritance are often described as forming an inheritance hierarchy. There is one class, referred to as the root, from which all the other classes inherit, directly or indirectly. In our bo
點(diǎn)擊復(fù)制文檔內(nèi)容
公司管理相關(guān)推薦
文庫(kù)吧 www.dybbs8.com
備案圖鄂ICP備17016276號(hào)-1