Zaraki's blog

By Zaraki, 12 years ago, In Russian

How to write in C++, when we using undefined(minus) position in array, that don't get Compilation Error. Example : a[-2][3] or a[-3][2] or a[-2][-3]; a — array;

  • Vote: I like it
  • +4
  • Vote: I do not like it

»
12 years ago, # |
Rev. 2   Vote: I like it +15 Vote: I do not like it

For example this way.

int *a = new int[11];
a += 5;
for(int i = -5; i <= 5; i++)
    a[i] = i;

Another approach is to use custom class with overloaded operator[].