Ever wonder how the C++ compiler actually tells the difference between overloaded functions?
We write functions with the exact same name and take the magic for granted. But under the hood, the linker requires a unique identifier for every single function.
The secret? Name Mangling.
Check out the image below! 👇
The compiler automatically alters the function's name based on the number and types of its arguments. To us, it’s just display(). To the compiler, they are two completely different entities (like i for int, d for double). The ambiguity is resolved before the code is even linked.
It's a great reminder of how much heavy lifting the compiler does behind the scenes to keep our APIs clean and readable.
What’s a concept you used for years before finally looking under the hood? Let's hear it below!
#CPP #Cplusplus #SoftwareEngineering #TechTrivia #Programming #BackendDevelopment
`reserve()` can be a lot more than just optimization, too! If you try to store entities in a vector, and pass some pointers around for those entities, you'll soon find everything going haywire, because the first time the vector resizes, all of those pointers dangle. `reserve()` allows you to make use of the vector rather than moving to maps or smart pointers.