c++ - Can you cast a pointer, into an array? -
i have pointer "a", of type a*. there n objects of type @ address , want iterate on them.
i cast a[n], can use c++11 range-for , write for (auto temp : a){...}
. of course, can use classic for(int i=0; i<n; i++) {temp=a[i]; ...}
range-for cleaner.
yes can do.
// allocate array of 1 int[2] dynamically // , store pointer int(*p)[2] = new int[1][2]; // initialize reference int(&array)[2] = *p; // delete array once no longer need delete[] p;
Comments
Post a Comment