Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I supply argument to delete[] like delete[3]?

I read that delete[] can deallocate an array of objects. However it is not mentioned in any of the sources I've read that whether it is an error or undefined to supply an argument like delete[3].

I have the following queries.

  1. Is it specified in C++ standard whether I can/cannot suplly a parameter to delete[] as delete[3]?
  2. If yes, what is the effect?
  3. Also is it specified in C++ whether I can/cannot use delete for an array allocated from new[]?
like image 601
pasha Avatar asked Feb 11 '16 12:02

pasha


2 Answers

(1) Yes, it specifies you can't.

(3) It specifies the outcome is undefined, so don't.

like image 131
StoryTeller - Unslander Monica Avatar answered Sep 19 '22 07:09

StoryTeller - Unslander Monica


delete[] is an operator.

delete[x] is not a valid c++ syntax, so the code wont compile.

like image 26
Praveen Avatar answered Sep 21 '22 07:09

Praveen