Презентация Nheritance, polymorphism, and virtual functions онлайн

На нашем сайте вы можете скачать и просмотреть онлайн доклад-презентацию на тему Nheritance, polymorphism, and virtual functions абсолютно бесплатно. Урок-презентация на эту тему содержит всего 48 слайдов. Все материалы созданы в программе PowerPoint и имеют формат ppt или же pptx. Материалы и темы для презентаций взяты из открытых источников и загружены их авторами, за качество и достоверность информации в них администрация сайта не отвечает, все права принадлежат их создателям. Если вы нашли то, что искали, отблагодарите авторов - поделитесь ссылкой в социальных сетях, а наш сайт добавьте в закладки.
Презентации » Устройства и комплектующие » Nheritance, polymorphism, and virtual functions



Оцените!
Оцените презентацию от 1 до 5 баллов!
  • Тип файла:
    ppt / pptx (powerpoint)
  • Всего слайдов:
    48 слайдов
  • Для класса:
    1,2,3,4,5,6,7,8,9,10,11
  • Размер файла:
    765.95 kB
  • Просмотров:
    63
  • Скачиваний:
    0
  • Автор:
    неизвестен



Слайды и текст к этой презентации:

№1 слайд
Lesson Inheritance,
Содержание слайда: Lesson 15 Inheritance, Polymorphism, and Virtual Functions

№2 слайд
What Is Inheritance? Provides
Содержание слайда: What Is Inheritance? Provides a way to create a new class from an existing class The new class is a specialized version of the existing class

№3 слайд
Example Insect Taxonomy
Содержание слайда: Example: Insect Taxonomy

№4 слайд
The quot is a quot
Содержание слайда: The "is a" Relationship Inheritance establishes an "is a" relationship between classes. A poodle is a dog A car is a vehicle A flower is a plant A football player is an athlete

№5 слайд
Inheritance Terminology and
Содержание слайда: Inheritance – Terminology and Notation in C++ Base class (or parent) – inherited from Derived class (or child) – inherits from the base class Notation: class Student // base class { . . . }; class UnderGrad : public student { // derived class . . . };

№6 слайд
Back to the is a Relationship
Содержание слайда: Back to the ‘is a’ Relationship An object of a derived class 'is a(n)' object of the base class Example: an UnderGrad is a Student a Mammal is an Animal A derived object has all of the characteristics of the base class

№7 слайд
What Does a Child Have? An
Содержание слайда: What Does a Child Have? An object of the derived class has: all members defined in child class all members declared in parent class An object of the derived class can use: all public members defined in child class all public members defined in parent class

№8 слайд
Protected Members and Class
Содержание слайда: Protected Members and Class Access protected member access specification: like private, but accessible by objects of derived class Class access specification: determines how private, protected, and public members of base class are inherited by the derived class

№9 слайд
Class Access Specifiers
Содержание слайда: Class Access Specifiers public – object of derived class can be treated as object of base class (not vice-versa) protected – more restrictive than public, but allows derived classes to know details of parents private – prevents objects of derived class from being treated as objects of base class.

№10 слайд
Inheritance vs. Access
Содержание слайда: Inheritance vs. Access

№11 слайд
Inheritance vs. Access
Содержание слайда: Inheritance vs. Access

№12 слайд
Inheritance vs. Access
Содержание слайда: Inheritance vs. Access

№13 слайд
Inheritance vs. Access
Содержание слайда: Inheritance vs. Access

№14 слайд
Constructors and Destructors
Содержание слайда: Constructors and Destructors in Base and Derived Classes Derived classes can have their own constructors and destructors When an object of a derived class is created, the base class’s constructor is executed first, followed by the derived class’s constructor When an object of a derived class is destroyed, its destructor is called first, then that of the base class

№15 слайд
Constructors and Destructors
Содержание слайда: Constructors and Destructors in Base and Derived Classes

№16 слайд
Constructors and Destructors
Содержание слайда: Constructors and Destructors in Base and Derived Classes

№17 слайд
Constructors and Destructors
Содержание слайда: Constructors and Destructors in Base and Derived Classes

№18 слайд
Passing Arguments to Base
Содержание слайда: Passing Arguments to Base Class Constructor Allows selection between multiple base class constructors Specify arguments to base constructor on derived constructor heading: Square::Square(int side) : Rectangle(side, side) Can also be done with inline constructors Must be done if base class has no default constructor

№19 слайд
Passing Arguments to Base
Содержание слайда: Passing Arguments to Base Class Constructor

№20 слайд
Redefining Base Class
Содержание слайда: Redefining Base Class Functions Redefining function: function in a derived class that has the same name and parameter list as a function in the base class Typically used to replace a function in base class with different actions in derived class

№21 слайд
Redefining Base Class
Содержание слайда: Redefining Base Class Functions Not the same as overloading – with overloading, parameter lists must be different Objects of base class use base class version of function; objects of derived class use derived class version of function

№22 слайд
Base Class
Содержание слайда: Base Class

№23 слайд
Derived Class
Содержание слайда: Derived Class

№24 слайд
Driver Program
Содержание слайда: Driver Program

№25 слайд
Problem with Redefining
Содержание слайда: Problem with Redefining Consider this situation: Class BaseClass defines functions x() and y(). x() calls y(). Class DerivedClass inherits from BaseClass and redefines function y(). An object D of class DerivedClass is created and function x() is called. When x() is called, which y() is used, the one defined in BaseClass or the the redefined one in DerivedClass?

№26 слайд
Problem with Redefining
Содержание слайда: Problem with Redefining

№27 слайд
Class Hierarchies
Содержание слайда: Class Hierarchies

№28 слайд
Class Hierarchies
Содержание слайда: Class Hierarchies

№29 слайд
Polymorphism and Virtual
Содержание слайда: Polymorphism and Virtual Member Functions Virtual member function: function in base class that expects to be redefined in derived class Function defined with key word virtual: virtual void Y() {...} Supports dynamic binding: functions bound at run time to function that they call Without virtual member functions, C++ uses static (compile time) binding

№30 слайд
Polymorphism and Virtual
Содержание слайда: Polymorphism and Virtual Member Functions

№31 слайд
Содержание слайда:

№32 слайд
Содержание слайда:

№33 слайд
Static Binding Program -
Содержание слайда: Static Binding Program 15-10 displays 'C' instead of 'P' because the call to the getLetterGrade function is statically bound (at compile time) with the GradedActivity class's version of the function. We can remedy this by making the function virtual.

№34 слайд
Virtual Functions A virtual
Содержание слайда: Virtual Functions A virtual function is dynamically bound to calls at runtime. At runtime, C++ determines the type of object making the call, and binds the function to the appropriate version of the function.

№35 слайд
Virtual Functions To make a
Содержание слайда: Virtual Functions To make a function virtual, place the virtual key word before the return type in the base class's declaration: virtual char getLetterGrade() const; The compiler will not bind the function to calls. Instead, the program will bind them at runtime.

№36 слайд
Updated Version of
Содержание слайда: Updated Version of GradedActivity

№37 слайд
Polymorphism
Содержание слайда: Polymorphism

№38 слайд
Содержание слайда:

№39 слайд
Содержание слайда:

№40 слайд
Polymorphism Requires
Содержание слайда: Polymorphism Requires References or Pointers Polymorphic behavior is only possible when an object is referenced by a reference variable or a pointer, as demonstrated in the displayGrade function.

№41 слайд
Base Class Pointers
Содержание слайда: Base Class Pointers

№42 слайд
Base Class Pointers Base
Содержание слайда: Base Class Pointers Base class pointers and references only know about members of the base class So, you can’t use a base class pointer to call a derived class function Redefined functions in derived class will be ignored unless base class declares the function virtual

№43 слайд
Redefining vs. Overriding In
Содержание слайда: Redefining vs. Overriding In C++, redefined functions are statically bound and overridden functions are dynamically bound. So, a virtual function is overridden, and a non-virtual function is redefined.

№44 слайд
Virtual Destructors It s a
Содержание слайда: Virtual Destructors It's a good idea to make destructors virtual if the class could ever become a base class. Otherwise, the compiler will perform static binding on the destructor if the class ever is derived from. See Program 15-14 for an example

№45 слайд
Abstract Base Classes and
Содержание слайда: Abstract Base Classes and Pure Virtual Functions Pure virtual function: a virtual member function that must be overridden in a derived class that has objects Abstract base class contains at least one pure virtual function: virtual void Y() = 0; The = 0 indicates a pure virtual function Must have no function definition in the base class

№46 слайд
Abstract Base Classes and
Содержание слайда: Abstract Base Classes and Pure Virtual Functions Abstract base class: class that can have no objects. Serves as a basis for derived classes that may/will have objects A class becomes an abstract base class when one or more of its member functions is a pure virtual function

№47 слайд
Multiple Inheritance
Содержание слайда: Multiple Inheritance

№48 слайд
Multiple Inheritance Problem
Содержание слайда: Multiple Inheritance Problem: what if base classes have member variables/functions with the same name? Solutions: Derived class redefines the multiply-defined function Derived class invokes member function in a particular base class using scope resolution operator :: Compiler errors occur if derived class uses base class function without one of these solutions

Скачать все slide презентации Nheritance, polymorphism, and virtual functions одним архивом: