Polymorphism makes no sense?

I've trying to understand this concept for the past week, I just can't get it. Not even a bit of it :( Can someone explain it to me in the easiest way possible please? Thanks in advance.
http://www.cplusplus.com/doc/tutorial/polymorphism/

If you read this an don't understand, then what EXACTLY do you not get?
Last edited on
If C++ STL can get away from polymorphism with template replacement, then I think not knowing polymorphism is not really a show-stopper in your C++ development isn't it ? :)
Polymorphism is one of the most special, if not the THE most special, of all C++ features. Using templates will limit you to writing code at compile time and doing unnecessary casts. +1 to L B, what do you not get about it, what do you think it is, right now?

- Dutch guy with the Japanese name
Polymorphism seem to arise out of OO theories. So in theory any OO programming languages would have this feature. Java is one I know and many others. But C++ is different, it attempt to be OO and yet it can still be non-OO.

Inheritance is vertical depth. C++ templates is horizontal depth AND also support vertical depth.

So not knowing polymorphism or inheritance does not stop one from developing C++ programs effectively.
Let's think of it like this. Say you have a class Person. Suppose it has methods like march() or attack()

From the class person we derive the classes like Army, Navy, Airforce

If you like these soldiers to attack then you have to command them all one by one like this
1
2
3
4
5
6
Army* bob = new Army();
Navy* scoth = new Navy();
Airforce* tom = new Airforce();
bob.attack();
scoth.attack();
tom.attack();



Using polymorphism you command these soldiers something like this
1
2
3
4
5
6
Person* myArmy[3];
myArmy[0] = new Army();
myArmy[1] = new Navy();
myArmy[2] = new Airforce();
for(int i=0; i<3; i++)
  myArmyp[i].attack();

Wasn't there just a thread like this? Heh.

Anyway, here was my reply to a previous thread where I tried to explain polymorphism. I think my last post in it does a pretty decent job:

http://cplusplus.com/forum/beginner/28170/#msg152257
Topic archived. No new replies allowed.