E2158 Operand of 'delete' must be non-const pointer (C++)

From RAD Studio
Jump to: navigation, search

Go Up to Compiler Errors And Warnings (C++) Index

It is illegal to delete a variable that is not a pointer. It is also illegal to delete a pointer to a constant.

For example:

const int x=10;
   const int * a = &x;
   int * const b = new int;
   int &c = *b;
   delete a;   //illegal - deleting pointer to constant
   delete b;   //legal
   delete c;   //illegal - operand not of pointer type
               //should use 'delete&c' instead