|
|
|
|
|
by nly
4428 days ago
|
|
This is because delete is an operator that can be overridden, and whether it has been overridden isn't known until link time. void operator delete(void*) { }
int main()
{
int on_stack;
int& ref = on_stack;
int* ptr = &ref;
delete ptr;
return 0;
}
and now it's safe :P... and yes, never freeing any memory is arguably a perfectly valid memory management strategy. Ok, this example is nuts... but it's a feature of C++, in the C tradition, that it lets you do crazy things. Can I plug custom per-type memory allocators in to Rust? |
|