3 ms·
That's a great summary! I'm always disappointed if people only know one kind of polymorphism and apply that rigorously to all problems. Overviews like this mig
by vog 16y ago
That's a great summary!
I'm always disappointed if people only know one kind of polymorphism and apply that rigorously to all problems. Overviews like this might help people to make a conscious decision on which language construct would be a good fit for their actual design problem.
- Chris_Newton 16y agoThat's a fair point, but unfortunately in C++ the various types of polymorphism often do not play nicely together. Look at any on-line forums discussing C++. If you're a bit more cynical, look at a list of tricky C++ interview questions instead. :-) You'll find discussions about overloading vs. overriding for class member functions. You'll find discussions of which function gets called when you have both overloaded functions and function templates to consider. You'll find discussions of which sequences of implicit conversions are allowed, and via what mechanisms. A very high proportion of the nasty edge cases for which C++ has become infamous are caused by trying to combine different forms of polymorphism. I'm all for knowing your tools and evaluating all the options, but I can see why in practice a lot of teams do stick almost entirely to (for example) using classes/OOP and avoiding templates.
- DougBTX 16y agoI get the impression that the answer is no, but is there much use of templates in C++ to make generic classes like in Java/C#?
- obiterdictum 16y agoIt may be a good summary, but I completely disagree with author's (implied) assertion that all these should be lumped under one term. All these concepts are different in their mechanics, which is the reason we have different terminology to describe them. Just call overloading overloading. C++ does not need more ambiguity, it needs less.
- scott_s 16y agoI sympathize with your point, but I used to think of runtime and parametric polymorphism as two completely separate things. It wasn't until I heard them both described as a type of polymorphism that I realized the relationship between them.
- pkrumins 16y agoI never implied that they should lumped under one term. On the contrary. I wrote out all the meanings the term can have to disambiguate it.
- seliopou 16y agoThe blog post is titled "The Four Polymorphisms in C++."
- pkrumins 16y agoYes, the four polymorphisms you can find in C++. Am I missing something?
- dkarl 16y agoYou're missing the fact that "polymorphism" has an established meaning in C++ which excludes two of your examples. You're using a definition of polymorphism that is independent of C++ and applying it to C++, which is certainly a valid exercise, but you haven't bothered to tell us what your definition is or explain why it applies to each example. If I assume that by "polymorphism" you mean when a single name can be used to refer to different things, then consider the following: void foo(float f); int main() { foo(1); return 0; } What name is polymorphic here? I suppose you can say that foo is polymorphic if you attribute the coercion operation to foo, but that's not the way I think about it. foo is called after the coercion. The coercion is caused by the relation of the type of 1 with the type of the function parameter f. In your blog post it would have made things much clearer if you had acknowledged the conventional usage of the term in the context of C++ and explained the different definition you were using.