I have an abstract base class Exercise
with virtualvoid presentSpecific()const=0;
and two sub-classes Weight and cardio.
and now I would like to crate a main where i declare two pointers of the base class type.
Create an object of each exercise type and make em present them selves on the screen.
Just that your C-style casts don't belong there (use dynamic_cast for this), and you don't really use polymorphism like that - polymorphism is used to provide an interface for interacting with an object, without having to know the concrete type of that object.
Its an old assignment from an examination, and its stated that I should have pointers.
why doesn't it work?
I get the correct couts.
Our professor showed us three was we can handle this.
1. typeid (as I did)
2. clone()
3. dynamic_cast
I use typeid bcs he uses only that one, and it is in all examples he has written.
And when he has to do it for an assignment, he should do just that. Of course it doesn't make very much sense, but it's just to introduce the concept of polymorphism here. My only complaint with his code are the C-Style casts he uses.