gpt4 book ai didi

ios - 数组类型 'int [16]' 不可分配

转载 作者:可可西里 更新时间:2023-11-01 03:37:51 26 4
gpt4 key购买 nike

我正在使用最新的 SDK 开发 iOS 应用程序。

我想在 .mm 文件上执行此操作:

@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};
}

...
}

但是我得到以下错误:

Array type 'int [16]' is not assignable

我该如何修复这个错误?

最佳答案

如果你只想初始化数组:

int _cars[16] = {0};

删除多余的零是安全的,编译器会找出它们。在 C 中不可能分配整个数组,这就是编译器在您的情况下提示的原因。只能对它们进行初始化,并且赋值仅在​​作为声明的一部分完成时才被视为初始化。

关于ios - 数组类型 'int [16]' 不可分配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15207977/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com