C ++ Inheritance.

Slides:



Advertisements
Similar presentations
Inheritance. Many objects have a hierarchical relationship –Examples: zoo, car/vehicle, card game, airline reservation system Inheritance allows software.
Advertisements

C++ Classes & Data Abstraction
Chapter 1 OO using C++. Abstract Data Types Before we begin we should know how to accomplish the goal of the program We should know all the input and.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation - a language mechanism for restricting access to some.
Shallow Versus Deep Copy and Pointers Shallow copy: when two or more pointers of the same types point to the same memory – They point to the same data.
Virtual Functions Fall 2008 Dr. David A. Gaitros
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 28P. 1Winter Quarter Inheritance and Overloading.
Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes
C++ Programming: Program Design Including Data Structures, Fourth Edition Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes.
1 Classes- Inheritance Multiple Inheritance It is possible to derive a new class from more than one base class. This is called Multiple Inheritance. Under.
C++ Programming: From Problem Analysis to Program Design, Fourth Edition Chapter 14: Pointers, Classes, Virtual Functions, and Abstract Classes.
Intro to C++ for Robotics Made for ALARM. Computer System Hardware – cpu, memory, i/o Software – OS, drivers.
Polymorphism &Virtual Functions
CSE 332: C++ templates This Week C++ Templates –Another form of polymorphism (interface based) –Let you plug different types into reusable code Assigned.
Inheritance Joe Meehean. Object Oriented Programming Objects state (data) behavior (methods) identity (allocation of memory) Class objects definition.
Object Oriented Programming with C++/ Session 6 / 1 of 44 Multiple Inheritance and Polymorphism Session 6.
Understanding Structures tMyn1 Understanding Structures In order to describe virtually anything in the real world, you need to define several values that.
Data Structures Using C++ 2E Chapter 3 Pointers. Data Structures Using C++ 2E2 Objectives Learn about the pointer data type and pointer variables Explore.
Chapter 12: Pointers, Classes, Virtual Functions, and Abstract Classes.
An Object-Oriented Approach to Programming Logic and Design Chapter 3 Using Methods and Parameters.
11 Introduction to Object Oriented Programming (Continued) Cats.
Topic 1 11/18/2015. Submitted By: Arslan Ali : Roll No: 6703 Ali Ahmad : Roll No: 6710 Ameer Moavia : Roll No: 6734 Abdul Manam : Roll No: 6738 Agha Waqas.
C/C++ 3 Yeting Ge. Static variables Static variables is stored in the static storage. Static variable will be initialized once. 29.cpp 21.cpp.
Computer Programming & Applications Mohamed Iqbal Pallipurath Lecture 02P. 1 Inheritance and Overloading Lecture 28.
Pointers A pointer is a variable that contains a memory address as it’s value. The memory address points to the actual data. –A pointer is an indirect.
Lecture 19 CIS 208 Wednesday, April 06, Welcome to C++ Basic program style and I/O Class Creation Templates.
Operator Overloading: indexing Useful to create range-checked structures: class four_vect { double stor[4]; // private member, actual contents of vector.
OOP using C Abstract data types How to accomplish the task??? Requirements Details Input, output, process Specify each task in terms of input.
16-1 Computing Fundamentals with C++ Object-Oriented Programming and Design, 2nd Edition Rick Mercer Franklin, Beedle & Associates, 1999 ISBN
Object Oriented Programming in C++ Chapter 7 Dynamic Binding.
Inheritance in C++ Bryce Boe 2012/08/28 CS32, Summer 2012 B.
Polymorphism and Virtual Functions One name many shapes behaviour Unit - 07.
Classes Classes are a major feature of C++. They support – – Abstraction – Data hiding – Encapsulation – Modularity – Re-use through inheritance.
1 Inheritance and Polymorphism Chapter Getting Started Continue the Cat Management example from previous presentation.
Chapter 12: Pointers, Classes, Virtual Functions, Abstract Classes, and Lists.
Polymorphism & Virtual Functions 1. Objectives 2  Polymorphism in C++  Pointers to derived classes  Important point on inheritance  Introduction to.
A First Book of C++ Chapter 12 Extending Your Classes.
Abstract classes only used as base class from which other classes can be inherit cannot be used to instantiate any objects are incomplete Classes that.
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
CS212: Object Oriented Analysis and Design
Classes and Inheritance
Chapter 13: Pointers, Classes, Virtual Functions, and Abstract Classes
Inheritance and Big O And your first reading assignment
C ++ Pointer code.
Quiz 11/15/16 – C functions, arrays and strings
C++, OBJECT ORIENTED PROGRAMMING
Inheritance and Overloading
Polymorphism & Virtual Functions
Checking Memory Management
Templates.
Chapter 12: Pointers, Classes, Virtual Functions, and Abstract Classes
Array of objects.
Chapter 14: Pointers, Classes, Virtual Functions, and Abstract Classes
Data Structures and Algorithms
Inheritance Virtual Functions, Dynamic Binding, and Polymorphism
Array of objects.
Virtual Functions Polymorphism is supported by C++ both at compile time and at run time. Compile-time polymorphism is achieved by overloading functions.
Welcome back to Software Development!
Inheritance Virtual Functions, Dynamic Binding, and Polymorphism
Today’s Objectives 10-Jul-2006 Announcements Quiz #3
CIS 199 Final Review.
Java Programming Language
Chapter 8 Inheritance Part 2.
Object – relational database
ㅎㅎ Sixth step for Learning C++ Programming Pointer new, delete String
COP 3330 Object-oriented Programming in C++
Chapter 11 Inheritance and Encapsulation and Polymorphism
Chapter 11 Classes.
Static Binding Static binding chooses the function in the class of the base class pointer, ignoring any versions in the class of the object actually.
Computer Science II for Majors
Presentation transcript:

C ++ Inheritance

Inheritance A derived class is an addition to a base class. The attributes and functions of the base class are available in the derived class, Almost private protected public

A base class X and a derived class Y

TTYP –derived class for book class catalog_item { char* title; char* catalog_number; public: catalog_item(){title = new char[MAX]; catalog_number = new char[MAX];} void addtitle (char* newtitle); void addcatnum(char* new catnum); void display(); }; TTYP1 – write declaration of attributes and functions TTYP2 – write definition of addbook

Library Object model

Storing base and derived instances A pointer to a base type can point to instances of derived classes Virtual functions will figure “right” function to apply type casting can let the compiler know when you know that the type is really something else.

TTYP3 - addbook Write an addbook function for the library class Assume that library has an array of pointers to catalog-items catalog-item *itemlist[MAX];

Redefining functions Must have the same return type Virtual functions puts indirection in object space

TTYP4 Write a display function for book

TTYP5 Write a virtual display function for cat-item

TTYP6 Write a display function for library