Hi,
Thank you all for your answears.
Sorry for the late answear :)
I've been looking for practical example but it will depends on the design of a project, so i'll give a generic example.
Imagine we have four class : ANIMAL, FLYER, DOG, CROWN.
class Animal {
public:
virtual ~Animal() {};
void talk (string sound) {
cout << " Grrrr " << (char *)&sound << endl;
}
};
class Flyer {
public:
void fly (string destination) {
cout << " Flying to " << (char *)&destination << endl;
}
};
class Dog:public Animal{
};
class Crow:public Animal, public Flyer{
};
To save the object of type Dog and Crow we need to do an upcast to the base class animal.
when we need to call a fly() method of each Crow we need to know if the animal inherits from Flyer class or not, this is done by a cross-cast :
Flyer* myAnimal = dynamic_cast<Flyer*>(pAnimal);
if(!myAnimal)
cout<<" my animal can't fly :( ..."<<endl;
else
cout<<" my animal can flye :) ..."<<endl;
I hope that it would be helpfull :).