Ambiguity Resolution in Inheritance

Slides:



Advertisements
Similar presentations
Chapter 5 Inheritance. Objectives Introduction, effects, and benefits of inheritance Base class and derived class objects Base class and derived class.
Advertisements

Copyright © 2012 Pearson Education, Inc. Chapter 13: Introduction to Classes.
Contents o Introduction o Characteristics of Constructor. o Types of constructor. - Default Constructor - Parameterized Constructor - Copy Constructor.
Review of Inheritance. 2 Several Levels of Inheritance Base Class B Derived class D Derived class D1.
Inheritance zThe mechanism by which one class can inherit the properties of another. zIt allows a hierarchy of classes to be built, moving from the most.
Sort the given string, without using string handling functions.
C++ Classes & Data Abstraction
Inheritance In C++  Inheritance is a mechanism for building class types from other class types defining new class types to be a –specialization –augmentation.
INHERITANCE By: Er. Gurpreet Singh Assistant Professor Department of Information Technology, Department of Information Technology, MIMIT Malout 1.
Learners Support Publications Inheritance: Extending Classes.
 2003 Prentice Hall, Inc. All rights reserved Multiple Inheritance Multiple inheritence –Derived class has several base classes –Powerful, but.
Inheritance: Extending classes Prepared By Prepared By : VINAY ALEXANDER ( विनय अलेक्जेण्डर )PGT(CS) KV JHAGRAKHAND.
VIRTUAL FUNCTIONS AND DYNAMIC POLYMORPHISM. *Polymorphism refers to the property by which objects belonging to different classes are able to respond to.
OBJECT ORIENTED PROGRAMMING LECTURE 12 Instructor: Rashi Garg Coordinator: Gaurav Saxena.
Learners Support Publications Pointers, Virtual Functions and Polymorphism.
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.
1 CSC241: Object Oriented Programming Lecture No 13.
Object Oriented Programming with C++/ Session 6 / 1 of 44 Multiple Inheritance and Polymorphism Session 6.
LECTURE 11 TYPES OF USER DEFINE FUNCTIONS ITC-414.
Unit IV Unit IV: Virtual functions concepts, Abstracts classes & pure virtual functions. Virtual base classes, Friend functions, Static functions, Assignment.
Introduction To Classes Chapter Procedural And Object Oriented Programming Procedural programming focuses on the process/actions that occur in a.
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.
Protectedly Inherited Base Class  When the access specifier of the base class in the derived class definition is protected, the base class is protectedly.
Inheritance: Base and Derived Classes. Introduction In dictionary inheritance is defined as the action of inheriting; the transfer of property; to receive.
Lecture 10 Concepts of Programming Languages Arne Kutzner Hanyang University / Seoul Korea.
Order of Constructor Call. Base class constructors are always called in the derived class constructors. Whenever you create derived class object, first.
 A constructor is a special member function whose task is to initialize the objects of its class.  It is special because its name is same as the class.
Constructor in Inheritance. 2 Constructors are used to initialized object. In inheritance the base class contains default constructor then, the base class.
Operator overloading: Overloading a unary operator is similar to overloading a binary operator except that there is one Operand to deal with. When you.
Chapter -6 Polymorphism
Chapter 9. Inheritance - Basics Inheritance is a mechanism that allows you to base a new class upon the definition of a pre-existing class Subclass inherits.
A class may de defined to automatically include the data members and member functions of an already existing class. New data members and member functions.
 Templates enable us to define generic classes and functions and thus provides support for generic programming. Generic types are used as parameters.
Friend Function. 2 Any data which is declared private inside a class is not accessible from outside the class. A non-member function cannot have an access.
Java Inheritance in Java. Inheritance Inheritance is a mechanism in which one object acquires all the properties and behaviors of parent object. The idea.
 Virtual Function Concepts: Abstract Classes & Pure Virtual Functions, Virtual Base classes, Friend functions, Static Functions, Assignment & copy initialization,
NESTED CLASS. Apa itu nested class ? Nested class is a class defined inside a class, that can be used within the scope of the class in which it is defined.
C++ CODES PART#04 1 COPY ENGR.SABA MUGHAL FROM COMPUTER SYSTEMS DEPARTMENT.
Operator Overloading Ritika Sharma.
Modern Programming Tools And Techniques-I
Friend functions.
Classes C++ representation of an object
CSC241: Object Oriented Programming
Class and Objects UNIT II.
Inheritance.
Templates.
2.7 Inheritance Types of inheritance
CONSTRUCTORS & DESTRUCTORS
Class A { public : Int x; A()
Object-Oriented Programming
Constructors & Destructors
Modern Programming Tools And Techniques-I Inheritance
COPY ENGR.SABA MUGHAL FROM COMPUTER SYSTEMS DEPARTMENT
Contents Introduction to Constructor Characteristics of Constructor
HYBRID INHERITANCE : AMBIGUITY REMOVAL
Inheritance Dr. Bhargavi Goswami Department of Computer Science
Operators.
Constructor Spl member fn auto ini of object
Polymorphism Polymorphism
By Muhammad Waris Zargar
CLASSES AND OBJECTS.
Inheritance:Concept of Re-usability
Institute of Petroloeum Technology, Gandhinagar
Classes C++ representation of an object
Inheritance -II.
Lecture 10 Concepts of Programming Languages
COP 3330 Object-oriented Programming in C++
CPP Programming Language
Computer Science II for Majors
Programming Fundamental-1
Presentation transcript:

Ambiguity Resolution in Inheritance

We May face a problem using the multiple Inheritance , When a function name appear in more then one base class Class M { public : void display() { cout<< “Class M” } }; Class N { Public: Void Display() { cout <<“ Class N “} }; Which Display() function is used by the Derived class when we inherit these two class .

 The problem can be solved by defining a named Instance within the derived class resolution operator with the function. class P : public M , Public N { void Display() M :: display(); } }; Void main() { P p; P.display(); }

The Ambiguity may also Arise in a single Inheritance . Example Class A { Public : void Display() { cout<<“A”; }}; Class B : public A { cout<<“B”; }}; The Function in the Derived class overrides the inherited function So a simple call to display() function by B type object will invoke function defined in B Only But We may Invoke the function Display () defined in Class A by using the Scope Resolution operator to Specify the class

Int main() { B b ; b. display(); // invoke display() in B b Int main() { B b ; b.display(); // invoke display() in B b.A::display() // invoke display() in A b.B::display() // Invoke display() In B }

Nesting of classes Inheritance is the mechanism of deriving certain properties of one class into another . When a class contains objects of another class or its members, this kind of relationship is called containership or nesting . The class which contains objects of another class as its members is called as container class.

Class alpha {…… }; Class beta {……}; Class gamma { alpha a; // a is an object of alpha class beta b; // b is an object of beta class }; All the objects of gamma class will contain the object and b . This kind of relationship is called containership or nesting Creation of an object that contains another object is different then the creation of an independent object.

#include<iostream.h> class A                {            int a;                               public:                               void get();        }; class B                {            int b;                               A t;         // object t of class A is declare in class B                               void getdata();      }; void A :: get() {            cin>>a;                cout<<a; } void B :: getdata() {              cin>>b;                cout<<b;                t.get(); }                  //calling of get() of class A in getdata() of class B

void main() {              Clrscr();                B ab;                ab.getdata();                getch(); }