Take the address of a one-past-the-end array element via subscript: legal by the C++ Standard or not?

后端 未结 13 1372
傲寒
傲寒 2020-11-22 06:34

I have seen it asserted several times now that the following code is not allowed by the C++ Standard:

int array[5];
int *array_begin = &array[0];
int *ar         


        
13条回答
  •  遇见更好的自我
    2020-11-22 06:53

    In addition to the above answers, I'll point out operator& can be overridden for classes. So even if it was valid for PODs, it probably isn't a good idea to do for an object you know isn't valid (much like overriding operator&() in the first place).

提交回复
热议问题