










Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!











int main(){
int main(){
Phone obj;
Phone obj;
obj.Transmit();
obj.Transmit();
obj.Receive();
obj.Receive();
return 0;
return 0;
int main(){
int main(){
Phone obj;
Phone obj;
Transmitter * tPtr = &obj;
Transmitter * tPtr = &obj;
Receiver * rPtr = &obj;
Receiver * rPtr = &obj;
return 0;
return 0;
►
► 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
class LandVehicle{
class LandVehicle{
public:
public:
int GetMaxLoad(); int GetMaxLoad();
}; };
class WaterVehicle{ class WaterVehicle{
public:
public:
int GetMaxLoad();
int GetMaxLoad();
};
};
►
► 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
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{
};
};
int main(){
int main(){
AmphibiousVehicle obj;
AmphibiousVehicle obj;
obj.LandVehicle::GetMaxLoad();
obj.LandVehicle::GetMaxLoad();
obj.WaterVehicle::GetMaxLoad();
obj.WaterVehicle::GetMaxLoad();
return 0;
return 0;
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{
};
};
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{
};
};