Article ID: 131322 - View products that this article applies to.
This article was previously published under Q131322
This article has been archived. It is offered "as is" and will no longer be updated.
Attempting to delete a pointer to a constant causes the compiler to generate the following correct error message:
NOTE: Visual C++ .NET compiler does not demonstrate this issue in conformance to the changes made in the C++ ANSI Standards.
Error C2710 : cannot delete a pointer to a const object
Deleting a pointer to a constant should not be allowed by definition (ARM section 5.3.4) because it modifies the object pointed to. However, if you deliberately or accidentally use the explicit conversion, the compiler doesn't generate the error. The consequences of a such attempt are unpredictable and compiler implementation dependent.
Sample Code #1 to Demonstrate Behavior
Visual C++ version 5.0 and 6.0 generate the following error:
Error C2664: 'delete' : cannot convert parameter 1 from 'const char *' to 'void *'
Sample Code #2 to Demonstrate Behavior
For more information, see The Annotated C++ Reference Manual (1994) section 5.3.4.
Article ID: 131322 - Last Review: February 28, 2014 - Revision: 5.0
Contact us for more help