BUG: Deleting Pointer of Pointer Gives Ambiguous Error Message

Last reviewed: July 18, 1997
Article ID: Q130218
1.00 1.50 1.51 1.52 WINDOWS kbprg kbfixlist kbbuglist

The information to this article applies to :

  • The Microsoft C/C++ Compiler (CL.EXE) incuded with: Microsoft Visual C++ for Windows, versions 1.0, 1.5, 1.51, 1.52

SYMPTOMS

An attempt to delete a pointer to a pointer to a const causes the compiler to generate the following ambiguous error message:

Error C2665 : 'delete' : 4 overloads have no legal conversion

               for parameter 1

RESOLUTION

To resolve this problem, use delete with a cast expression, as shown here:

   delete [] cast-expression

   -or-

   delete cast-expression

You can also resolve the problem by using the following code:

   /*The following program resolves the problem:

   tyepedef const char *constcharstar;

   void main(void)
   {
      int num = 5;

      constcharstar *sects = new constcharstar[num];
      sects[2] = "abcd";

   delete [] (char **) sects;// suggested resolution for error C2665
                             // or " delete (char **) sects; "

   }

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug was corrected in Visual C++ for Windows NT, versions 1.0, 2.0, and 2.1.

MORE INFORMATION

Sample Code to Reproduce Problem

/* No special compile options needed. */
/* The following program reproduces the problem:

typedef const char *constcharstar;

void main(void)
{
   int num = 5;

   constcharstar *sects = new constcharstar[num];
   sects[2] = "abcd";

   delete  sects; // error C2665 , ambiguous error

}


Additional reference words: 1.00 1.50 1.51 1.52 8.00 8.00c no32bit noupdate
KBCategory: kbprg kbfixlist kbbuglist
KBSubcategory: CPPIss
Keywords : CPPIss kb16bitonly kbbuglist kbfixlist kbprg
Version : 1.00 1.50 1.51 1.52
Platform : WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 18, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.