The C++ Programming Language Third Edition phần 5

Casting từ lớp cơ sở al av ir từ một lớp học có nguồn gốc là thảo luận trong § . vi rt ua l Sử dụng đa kế thừa sử dụng đơn giản và rõ ràng nhất của đa kế thừa là "keo" hai lớp khác không liên quan với nhau như một phần của việc thực hiện các | Section Programming Virtual Bases 399 void Window _with_border draw Window draw own_draw display the border void Window _with_menu draw Window draw own_draw display the menu void Clock draw Window draw Window_with_border own_draw Window_with_menu own_draw own_draw display the clock face and hands Casting from a virtu al base class to a derived class is discussed in . Using Multiple Inheritance The simplest and most obvious use of multiple inheritance is to glue two ohsewrise unrelated classes together as part of the implementation of a third class. The Satellite class built out of the Task and Displayed classes in is an example of this. This use of multiple inheritance is crude effective and important but not very interesting. Basically it saves the programmer from writing a lot of forwarding functions. This technique does not affect the overall design of a program significantly and can occasionally clash with the wish to keep implementation details hidden. However a technique doesn thaveto becleverto beuseful. Using multiple inheritance to provide implementations for abstract classes is more fundamental in that it affects the way a program is designed. Class BB_ival_slider is an example class BB_ival_slider public Ival_slider interface protected BBslider implementation implementation of functions required by Ival_slider and BBslider using the facilities provided by BBslider In this example the two base classes play logically distinct roles. One base is a public abstract class providing the interface and the other is a protected concrete class providing implementation details. THcsc rotes arc rcftcctcd in both the slytc of the cksssss and in tì access control provided. The use of multiple inheritance is close to essential here because the derived class needs to override virtual functions from both the interface and the implementation. Multiple inheritance allows sibling classes to share information without introducing a

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
9    297    1    06-05-2024
Đã 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.