P
Philipp
Hello
This seems a simple question, please send me to the right FAQ if I
missed it:
If there is a class Fruits with two classes Apples and Bananas extending
Fruits. Apples has a method called isRed() which returns true if the
apple is red (Bananas don't have such a method)
Is it somehow possible to make code like this:
-- pseudo-code --
aMethod(Fruit* aFruit){
if (aFruit->getClass() == Apples) {
cout << "Is the apple red?:" << aFruit->isRed() << endl;
}
}
Does such a thing as getClass() exist (by default)?
Can I cast aFruit to an Apple pointer and test if the cast is valid?
Is there another nice (and light) way to implement it (except
implementing getClass() in Fruits and then in each child class)?
Thanks for your answers.
Philipp
This seems a simple question, please send me to the right FAQ if I
missed it:
If there is a class Fruits with two classes Apples and Bananas extending
Fruits. Apples has a method called isRed() which returns true if the
apple is red (Bananas don't have such a method)
Is it somehow possible to make code like this:
-- pseudo-code --
aMethod(Fruit* aFruit){
if (aFruit->getClass() == Apples) {
cout << "Is the apple red?:" << aFruit->isRed() << endl;
}
}
Does such a thing as getClass() exist (by default)?
Can I cast aFruit to an Apple pointer and test if the cast is valid?
Is there another nice (and light) way to implement it (except
implementing getClass() in Fruits and then in each child class)?
Thanks for your answers.
Philipp