Talk:cpp/memory/new/operator delete
From cppreference.com
< Talk:cpp
The second paragraph of "Class-specific overloads" has several issues:
- The dynamic dispatch only applies to delete object, not delete array (Essentially, parts of [class.free]/4 are missing, especially footnote 119, C++14 IS numbering.) Of course, delete array where the pointer points to a base class subobject is UB, and that's described on the page for the delete-expression.
- The paragraph does not mention which class is searched (though it's fairly obvious).
- Also, [class.free]/4 describes a slighly different lookup in the delete object case. The imporant criterion is not polymorphism of the type, but specifically the existence of a virtual destructor in the static type of the object (expression) to be deleted. Then, the lookup is performed from the point of definition of the final overrider of said virtual destructor. This ignores global deallocation functions declared after that point of definition.
See also: http://stackoverflow.com/q/28920482
dyp --84.162.29.49 15:00, 7 March 2015 (PST)
- I tried rewording that paragraph, it might use a micro-example. --Cubbi (talk) 08:14, 8 March 2015 (PDT)
Shouldn't 14 read:
14) Called by the standard array form of the placement new[] expression if...
Instead of:
14) Called by the standard array form of the placement new expression if...
ticotico (talk) 07:17, 21 April 2020 (PDT)
Not sure but shouldn't 15 and 16 read:
15) ... If a class-specific version (25) is defined, it is called in preference to (9) (15) ...
16) ... If a class-specific version (16) (26) is defined, it is called in preference to (10) (16) ...