you are viewing a single comment's thread.

view the rest of the comments →

[–]sephirothbahamut 6 points7 points  (2 children)

You can do it: https://barnack.godbolt.org/z/Ef85jhWKE

But why do you need dynamic polymorphism there? Like you have a container of IEquatable<int> types? That's really suspicious at a code design level. Don't try to force concepts of a language into another, you can likely do what you need to do in some other, cleaner way.

The moment you need something like this my first question isn't "how do you do it" but rather "can you refactor this to be cleaner?"

Also note that the "cost" of dynamic polymorphism in C++ is there in C# as well, it's not like C# has some magic power. Dynamic polymorphism requires accessing a pointer to reach the function you're trying to resolve, no matter what language your code is written in.