Compiler error on array declaration?

前端 未结 2 1651
深忆病人
深忆病人 2021-01-28 15:39

How do I go about fixing these three errors?

  • error C2057: expected constant expression
  • error C2466: cannot allocate an array of constant size 0
  • e
2条回答
  •  心在旅途
    2021-01-28 16:08

    Variable tickets is not a constant expression, that's why.

    Change int randomTickets[tickets][SIZE] as follows:

    Array* randomTickets = new Array[tickets];
    

    Outside of function main, declare the following type:

    typedef int Array[SIZE];
    

    You can use variable randomTickets as a "normal" 2-dimensional array from this point onwards, just don't forget to delete[] randomTickets when you're done...

提交回复
热议问题