2
//main.cpp
int main()
{
    int x[0];
    return 0;
}

//some class. for example stack
template<class T>
Stack::Stack(): _someParam(new T[0])
{ ... }

in first case VS13 says that i can not create array zero-size, but in the second case VS allow me to initialize array with size equals 0. Why does this happen?

Shafik Yaghmour
  • 154,301
  • 39
  • 440
  • 740
Oleh Kurpiak
  • 1,339
  • 14
  • 34
  • An array and a pointer are different types (`new T[0]` doesn't evaluate in an array but rather in a pointer) – 101010 Nov 11 '15 at 12:43
  • 3
    The suggested duplicate doesn't ask about the dynamic allocation of zero-size array, but the accepted answer does bring it up complete with quotes from the standard. – eerorika Nov 11 '15 at 12:45
  • @ShafikYaghmour the new duplicate does not answer why `int x[0];` is not allowed. The answer to the previous duplicate answered both that, and also why zero-sized dynamic array is OK. – eerorika Nov 11 '15 at 13:11
  • Why would you want to be allowed to declare an `int x[0]` ? Would it make any difference? – 463035818_is_not_an_ai Nov 11 '15 at 14:20
  • @tobi303, i just want to know what the differences between this methods – Oleh Kurpiak Nov 12 '15 at 14:55

0 Answers0