c++ passing 2d arrays to funcions

后端 未结 2 1077
既然无缘
既然无缘 2021-01-23 09:02

I know my code isnt finished yet im not asking for it to be done. It\'s supposed to input food eaten by 3 monkeys over a week and other stuff. But I\'ve hit a snag. It gives me

2条回答
  •  不思量自难忘°
    2021-01-23 09:45

    You've declared array as containing const doubles. They're constant, so you can't write to them as you are trying to do with cin >> array[index][count];. Just change the parameter declaration to:

    double array[][DAYS]
    

    Perhaps you should think about when and why you should declare a variable as const.

    As an aside to avoid later confusion, it's worth mentioning here that there's no such thing as array type parameters. The above parameter is actually transformed to:

    double (*array)[DAYS]
    

    However, your code is written appropriately to work with this (you passed the number of rows to the function).

提交回复
热议问题