note that
int *i
not fully interchangeable with
int i[]
This can be seen from the fact that the following will compile:
int *i = new int[5];
until it is:
int i[] = new int[5];
For the second, you must give it a list of constructors:
int i[] = {5,2,1,6,3};
You will also get some validation using the [] form:
int *i = new int[5]; int *j = &(i[1]); delete j;
compiles the warning for free, but:
int i[] = {0,1,2,3,4}; int j[] = {i[1]}; delete j;
issue warnings:
warning C4156: deleting an array expression without using the array form 'delete'; matrix form warning C4154: delete array expression; conversion to supplied pointer
Both of these last two examples will crash the application, but the second version (using the type of declaration []) will give a warning that you are shooting in the leg.
(Win32 console project C ++, Visual Studio 2010)
Patrickv
source share