Multiple Inheritance in Object-Oriented Programming: Ambiguity and Resolution, Slides of Object Oriented Programming

The concept of multiple inheritance in object-oriented programming (oop) and its implications on function ambiguity. It covers the transmitter and receiver classes, the mermaid example, and the ambiguous call problem. The document also provides solutions to the ambiguity problem and discusses the memory layout of derived classes.

Typology: Slides

2011/2012

Uploaded on 08/08/2012

anchita
anchita 🇮🇳

4.4

(7)

113 documents

1 / 18

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Object
Object-
-Oriented Programming
Oriented Programming
(OOP)
(OOP)
Lecture No. 31
Lecture No. 31
Multiple Inheritance
Multiple Inheritance
A class can inherit from more then one class
A class can inherit from more then one class
docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12

Partial preview of the text

Download Multiple Inheritance in Object-Oriented Programming: Ambiguity and Resolution and more Slides Object Oriented Programming in PDF only on Docsity!

Object

Object

Oriented Programming

Oriented Programming

(OOP)

(OOP)

Lecture No. 31

Lecture No. 31

Multiple Inheritance

Multiple Inheritance

Transmitter

Transmit()

Receiver

Receive()

Phone

Example

Example

int main(){

int main(){

Phone obj;

Phone obj;

obj.Transmit();

obj.Transmit();

obj.Receive();

obj.Receive();

return 0;

return 0;

Example

Example

int main(){

int main(){

Phone obj;

Phone obj;

Transmitter * tPtr = &obj;

Transmitter * tPtr = &obj;

Receiver * rPtr = &obj;

Receiver * rPtr = &obj;

return 0;

return 0;

Multiple Inheritance

Multiple Inheritance

► If more than one base class have a function

If more than one base class have a function

with same signature then the child will have

with same signature then the child will have

two copies of that function

two copies of that function

► Calling such function will result in ambiguity

Calling such function will result in ambiguity

Example

Example

class LandVehicle{

class LandVehicle{

public:

public:

int GetMaxLoad(); int GetMaxLoad();

}; };

class WaterVehicle{ class WaterVehicle{

public:

public:

int GetMaxLoad();

int GetMaxLoad();

};

};

Multiple Inheritance

Multiple Inheritance

► The ambiguous call problem can arise when

The ambiguous call problem can arise when

dealing with multiple level of multiple

dealing with multiple level of multiple

inheritance

inheritance

Example

Example

class Vehicle{

class Vehicle{

public:

public:

int GetMaxLoad(); int GetMaxLoad();

}; };

class LandVehicle : public Vehicle{ class LandVehicle : public Vehicle{

};

};

class WaterVehicle : public Vehicle{

class WaterVehicle : public Vehicle{

};

};

Example

Example

int main(){

int main(){

AmphibiousVehicle obj;

AmphibiousVehicle obj;

obj.LandVehicle::GetMaxLoad();

obj.LandVehicle::GetMaxLoad();

obj.WaterVehicle::GetMaxLoad();

obj.WaterVehicle::GetMaxLoad();

return 0;

return 0;

Example

Example

class Vehicle{

class Vehicle{

protected:

protected:

int weight; int weight;

}; };

class LandVehicle : public Vehicle{ class LandVehicle : public Vehicle{

};

};

class WaterVehicle : public Vehicle{

class WaterVehicle : public Vehicle{

};

};

Example

Example

class Vehicle{ class Vehicle{

protected:

protected:

int weight;

int weight;

}; };

class LandVehicle :

class LandVehicle :

public virtual Vehicle{ public virtual Vehicle{

}; };

class WaterVehicle :

class WaterVehicle :

public virtual Vehicle{ public virtual Vehicle{

};

};

Memory View

Memory View

Data Members of Vehicle

Data Members

of LandVehicle

Data Members of

AmphibiousVehicle

Data Members

of WaterVehicle