Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Array type 'int [16]' is not assignable

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?

like image 886
VansFannel Avatar asked Mar 04 '13 18:03

VansFannel


1 Answers

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.

like image 102
zoul Avatar answered Sep 29 '22 06:09

zoul