TAILIEUCHUNG - A Complete Guide to Programming in C++ part 62

A Complete Guide to Programming in C++ part 62. This book provides both novice and experienced programmers with a comprehensive resource manual for the C++ programming language. Readers gain experience in all aspects of programming, from elementary language concepts to professional software development, with in depth coverage of all the language elements en route. These elements are carefully ordered to help the reader create useful programs every step of the way. | MULTIPLY-DERIVED CLASSES 589 A class can contain not just one but several different base classes. In this case the class is derived from multiple base classes in a process known as multiple inheritance. The Multiply-Derived Class MotorHome This class Car is used to represent vehicles and the class Home contains characteristic values for an apartment such as floor space number and type of rooms and typical operations such as building selling or renting. Using these two classes you can then derive the MotorHome class. The opposite page shows the inheritance and definition schemes for the new class. An object of the MotorHome class contains both the members of Car and the members of Home. More specifically the object contains two base sub-objects of type Car and Home. Accessibility of Base Classes Since the MotorHome class has two public base classes it assumes the public interfaces of both classes. A MotorHome type object not only allows access to the additional public members but to all the public members of the base classes Car and Home. When defining a multiply-derived class the accessibility private protected or public must be defined separately for each base class. The MotorHome class could have the public base class Car and the protected base class Home. Example class MotorHome public Car protected Home . . . If the keyword is omitted the base class will default to private. Example class MotorHome public Car Home . . . This statement defines the public base class Car and the private base class Home. This makes all the public members in Home private members of the derived class. In multiple inheritance each public base class establishes an is relationship. This is similar to simple inheritance. If the MotorHome class inherits two public base classes a motor-home is a special kind of motor vehicle and a special kind of home. 590 CHAPTER 27 MULTIPLE INHERITANCE MULTIPLE INDIRECT BASE CLASSES The multiple indirect base class Car Definition scheme of class suv class

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.