如何使用c型数组作为伊娃? [英] How to use a c-type array as an ivar?

查看:132
本文介绍了如何使用c型数组作为伊娃?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要整数在我的程序一个老式的2维数组,但无论我如何努力将其声明为伊娃,然后用@财产/ @合成,我得到一个编译器的投诉或其他。

I need a good old-fashioned 2-dimensional array of integers in my program, but no matter how I try to declare it as an ivar, and then use @property/@synthesize, I get one compiler complaint or another.

我宣布

int spotLocations[10] [10]

作为伊娃。

这作品不多,但随后的@财产/ @合成过程中从来没有通过审核。

That much works, but then the @property/@synthesize process never passes muster.

推荐答案

您不能做到这一点。阵列variabless永远不能在C,这意味着你可以永远声明返回一个数组的函数左值,因为这将是不可能给函数的结果分配给一个数组变量(因为它不能是一个左值)。

You can't do this. Array variabless can never be lvalues in C, which means you can never declare a function that returns an array, because it would be impossible to assign the result of the function to an array variable (since it can't be an lvalue).

属性是声明返回类型的函数只是一个简便方法。由于函数永远不能返回数组,你永远不能声明一个属性,是一个数组。

Properties are just a shorthand way of declaring a function that returns a type. Since functions can never return arrays, you can never declare a property that is an array.

如果您确实需要移动矩阵左右这个样子,你可以包装在一个结构,它可以是左值:

If you absolutely need to move matrices around like this, you could wrap it in a struct, which can be lvalues:

typedef struct {
  int value[10][10];
} matrix;

...

@property matrix spotLocations;

当然,访问的地点是一个小更令人费解,你必须使用

Of course, accessing the locations is a little more convoluted, you have to use

spotLocations.value[x][y]

这篇关于如何使用c型数组作为伊娃?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆