C配列をObjective-Cプロパティとして宣言するのに問題があります(@propertyと@synthesizeを知っているので、ドット構文を使用できます)...これは3次元のint配列です。
1 に答える
5
できません--配列はCの左辺値ではありません。代わりにポインタプロパティを宣言し、正しいarrayboundsを使用するコードに依存するか、代わりにNSArray
プロパティを使用する必要があります。
例:
@interface SomeClass
{
int width, height, depth;
int ***array;
}
- (void) initWithWidth:(int)width withHeight:(int)height withDepth:(int)depth;
- (void) dealloc;
@property(nonatomic, readonly) array;
@end
@implementation SomeClass
@synthesize array;
- (void) initWithWidth:(int)width withHeight:(int)height withDepth:(int)depth
{
self->width = width;
self->height = height;
self->depth = depth;
array = malloc(width * sizeof(int **));
for(int i = 0; i < width; i++)
{
array[i] = malloc(height * sizeof(int *));
for(int j = 0; j < height; j++)
array[i][j] = malloc(depth * sizeof(int));
}
}
- (void) dealloc
{
for(int i = 0; i < width; i++)
{
for(int j = 0; j < height; j++)
free(array[i][j]);
free(array[i]);
}
free(array);
}
@end
array
次に、プロパティを3次元配列として使用できます。
于 2009-10-11T04:25:18.593 に答える