3 ms·
People use `new` and `delete` when explaining memory in C++ because those are the language primitives for allocating and releasing memory in C++. That rule of
by duped 9mo ago
People use `new` and `delete` when explaining memory in C++ because those are the language primitives for allocating and releasing memory in C++.
That rule of thumb is only a useful rule if you don't care about how memory works and are comfortable with abstractions like RAII. That's fine for lots of real code but dismissing `new` and `delete` on principle is not interesting or productive for any discussion.
- tialaramex 9mo agoAlso they're operators. I understand C++ has a lot of operators which are variously reserved but not standardized ("asm") largely obsolete but still needed because of perverse C programmers ("goto") still reserved long after their usefulness subsided ("register") or for ideas that are now abandoned ("synchronized") not to mention all its primitive types ("double", "signed", "long", "short", "char8_t") and redundant non-textual operators given ASCII names like ("and_eq", "bitand", "xor") But it also has dozens, like new and delete which look like features you'd want. So kinda makes sense to at least mention them in this context.
- tialaramex 9mo agoI think this got away from me, 'cos clearly part way through I start talking about keywords not operators, whoops.
- jurschreuder 9mo agoNo the primitives are: { // allocate auto my_obj = MyObj{} } // released