0

I found this among a supposedly trivial Tetris console game code.

wchar_t *screen = new wchar_t[];
unsigned char *pField;
.
.
.
screen[someMathIndex] = L" ABCDEFG=#"[pField[someOtherMathIndex]];

What is an wchar string in front of square brackets even mean? I can't even able to find a way to google it. Can you redirect me to some resource of this strange thing maybe.

Eugene Sh.
  • 17,802
  • 8
  • 40
  • 61
MILO
  • 15
  • 3

1 Answers1

5

String literals in C++ are actually arrays. I this case L" ABCDEFG=#" is a const wchar_t[11]. When you do

L" ABCDEFG=#"[pField[someOtherMathIndex]]

You are going to the pField[someOtherMathIndex]'th index of that wchar_t array.

NathanOliver
  • 171,901
  • 28
  • 288
  • 402
  • Never seen this. Thank you very much. – MILO Mar 22 '21 at 21:06
  • @MILO No problem. I've never seen someone do this either. Typically that string literal would be in a named variable like `wchar_t CoolString[] = L" ABCDEFG=#";` and then you would just have in the code `CoolString[pField[someOtherMathIndex]]` – NathanOliver Mar 22 '21 at 21:07