C is a simple language. You’re only allowed to have one function with each name. C++, on the other hand, gives you much more flexibility:
- You can have multiple functions with the same name (overloading).
- You can overload built-in operators like
+
and==
. - You can write function templates.
- Namespaces help you avoid naming conflicts.
I like these C++ features. With these features, you can make str1 + str2
return the concatenation of two strings. You can have a pair of 2D points, and another pair of 3D points, and overload dot(a, b)
to work with either type. You can have a bunch of array-like classes and write a single sort
function template that works with all of them.