I'm developing an iOS application with latest SDK.
I want to do this on a .mm
file:
@interface MyClass ()
{
int _cars[16];
...
}
@end
@implementation MyClass
-(id)init
{
self = [super init];
if (self)
{
_cars = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
}
...
}
But I get the following error:
Array type 'int [16]' is not assignable
How can I fix this error?
If you just want to initialize the array:
int _cars[16] = {0};
It’s safe to drop the extra zeros, the compiler will figure them out. It’s not possible to assign whole arrays in C, that’s why the compiler complains in your case. It’s only possible to initialize them, and the assignment is only considered to be initialization when when done as a part of the declaration.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With