Đang chuẩn bị liên kết để tải về tài liệu:
Lecture Programming in C++ - Chapter 15: Inheritance, virtual functions, and polymorphism

Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ

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 15.1 Image of base class object creation when derived class object instantiated Lesson 15.1 Derived class object Base class object Defining a Base Class Lesson 15.1 class Base { private: type base_priv_dat; protected: type base_prot_dat; public: type base_function_name ( ); }; Defining a Derived Class Lesson 15.1 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 15.1 Image of base class object creation when derived class object instantiated Lesson 15.1 Derived class object Base class object Defining a Base Class Lesson 15.1 class Base { private: type base_priv_dat; protected: type base_prot_dat; public: type base_function_name ( ); }; Defining a Derived Class Lesson 15.1 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 15.1 Relationship Between Base and Derived Objects Derived object Base object private data protected data public functions private data public functions derived_object.derived_function( ) derived_object.base_function( ) 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 15.1 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 15.1 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