Question 16
Back to Exercise
Why does void show(Animal a) { a.speak(); } always call Animal::speak, even for a Dog?
- A speak is not public
- B The Dog is copied into an Animal object (sliced), so the parameter really is an Animal Correct
- C Virtual functions do not work in functions
- D Animal must be abstract
Correct Answer: Option B
Take const Animal& (or a pointer) to keep the dynamic type.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!