Lecture Programming in C++ - Chapter 15: Inheritance, virtual functions, and polymorphism

Lecture Programming in C++ - Chapter 15: Inheritance, virtual functions, and polymorphism. In this chapter, you will learn to: Create an inheritance hierarchy, use inheritance as a form of class interaction, make a virtual class, use polymorphism in an engineering program. | Chapter 15 – Inheritance, Virtual Functions, and Polymorphism Inheritance Name of another way in which classes and objects relate Base class Derived class When object of derived class declared Object of base class is automatically created and contained within derived class object Lesson Image of base class object creation when derived class object instantiated Lesson Derived class object Base class object Defining a Base Class Lesson class Base { private: type base_priv_dat; protected: type base_prot_dat; public: type base_function_name ( ); }; Defining a Derived Class Lesson class Derived: public Base { private: int derived_priv_dat; public: void derived_function_name ( ); }; Interaction Between Base and Derived Class Objects Private base class members are private member of base class only Protected base class members are protected members of both derived and base classes Public base class members are public members of derived and base classes Derived . | Chapter 15 – Inheritance, Virtual Functions, and Polymorphism Inheritance Name of another way in which classes and objects relate Base class Derived class When object of derived class declared Object of base class is automatically created and contained within derived class object Lesson Image of base class object creation when derived class object instantiated Lesson Derived class object Base class object Defining a Base Class Lesson class Base { private: type base_priv_dat; protected: type base_prot_dat; public: type base_function_name ( ); }; Defining a Derived Class Lesson class Derived: public Base { private: int derived_priv_dat; public: void derived_function_name ( ); }; Interaction Between Base and Derived Class Objects Private base class members are private member of base class only Protected base class members are protected members of both derived and base classes Public base class members are public members of derived and base classes Derived class members convey no special access privileges to base class functions Lesson Relationship Between Base and Derived Objects Derived object Base object private data protected data public functions private data public functions ( ) ( ) No Base Class Object Name Use only derived object name to access both derived and base class functions Derived class takes precedence over-riding base class function Lesson Comparison of Types of Class and Object Interactions Friend class object Granting class object Client class object Server class object Component class object Composite Class Object Derived class object Base class object Lesson On all examples, upper boxes represent private data members and lower boxes represent public member functions. Private and Protected Inheritance class Derived : private Base public and protected members of Base become private members of Derived private members of Base remain private to Base

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
164    434    2    01-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.