开发者

iPhone dev get contents of C array in different class

I have a c array:

CGPoint hillKeyPo开发者_C百科ints[kMaxHillKeyPoints];

How do I access this from another class?

If I had an NSArray I would use a pointer to access the array, ie:

hillClass.[hillKeypoints objectAtIndex:0];

How does this work in c?

Thanks


C doesn't have classes. C just has structures and ordinary functions. Access is straightforward using one of the structure member access operators . or -> (depending on whether or not you have a pointer) and the array subscripting operator []:

typedef struct HillStruct
{
    CGPoint hillKeyPoints[kMaxHillKeyPoints];
} HillStruct;

void SomeFunction(HillStruct *hillStruct)
{
    // Read first member of the array in the structure
    CGPoint firstPoint = hillStruct->hillKeyPoints[0];
    // etc.
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜