BUG: Deleting Pointer of Pointer Gives Ambiguous Error Message

ID: Q130218

1.00 1.50 1.51 1.52 WINDOWS kbprg kbfixlist kbbuglist

The information to this article applies to :

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          : kb16bitonly kbCompiler kbCPPonly kbVC kbbuglist kbfixlist
Version           : 1.00 1.50 1.51 1.52
Platform          : WINDOWS

Last Reviewed: July 22, 1997