2 ms·
The point I was trying to make, that the line is often blurred between language features and standard library calls. C++'s new could've been a function, just li
by torginus 5y ago
The point I was trying to make, that the line is often blurred between language features and standard library calls. C++'s new could've been a function, just like C - it's how std::make_unique works.
- tialaramex 5y agoIt's an operator, and in C++ operators are basically just functions with some syntax sugar because of the extensive overloading. However, C++ doesn't have a single base class, so by making new an operator, it has a default implementation in every type whereas there is nowhere to write a function with that behaviour. This doesn't matter for malloc because C doesn't have a type hierarchy. Edited to add: std::make_unique always makes the thing std::make_unique wants to make, you can't overload that for your new type where it should do something else.