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.
}
精彩评论