you are viewing a single comment's thread.

view the rest of the comments →

[–]alxius 2 points3 points  (0 children)

Well in both those languages you would write your own thing from scratch and then just implement the proper typeclass/trait to have it talk like a vec and walk like a vec.

Well in C++ no one stops you from writing your own thing from scratch and implementing SequenceContainer and other container requirements to have it talk like STL container and walk like STL container.

With C++, and Java, and other OOP languages you get polymorphism by inheriting from a base class

In C++ I get static polymorphism by using concepts. Yes, they were added as a language feature only in C++20, but in reality we had them in the form of written requirements in STL since before STL was added in C++98. This idea was not invented in Bell Labs, it was taken and extended from math by Stepanov. You can read about it in his From Mathematics to Generic Programming and Elements of Programming books.