I am well aware of the const pointer to pointer problem, and I thought I knew what was going on, but boy I was wrong. I want to achieve this:
int* var[4];
const int* const (&refArray)[4] = var; //compile error
Yes, I want to preserve the array instead of converting to pointer, and yes I actually met this problem in my code. So I went on to investigate what I can and cannot do, before long I realize I have no idea what's going on:
int* var[4];
const int* const * ptr = var; //allowed
const int* const * (&refPtr_indirect) = ptr; //allowed
const int* const * (&refPtr) = var; //error
const int* const * const (&constRefPtr) = var; //allowed
int* const (&refArray)[4] = var; //allowed
const int* const (&refArray)[4] = var; //error
I can understand the first four, but the last two makes absolutely no sense to me. I do see that the third version may work and that I can drop the reference
, but I really hope to preserve the array type.
Any help is appreciated, but hopefully it can include the reasoning behind why the rules are as it is.