Please see comment:
static void drawAnObject() {
Form *form = [[Form alloc] init];
int i;
[form randomizeCube];
glColor3f(0.0, 0.0, 0.0);
for(i = 0; i < MAX_CUBE; i++) {
glutWireCube(form->cube[i]->size);
//compiler issues hard warning because form->cube is protected!!
}
}
I would rather use the accessor I placed on the "Form" class so I could rather write something like:
glutWireCube([[form cube][i] size]);
But I get a "cannot convert to a pointer type" error when I attempt to compile this.
This is my accessor in the "Form" class:
@implementation Form
- (Cube *) cube {
return *cube;
}
The variable "cube" is defined in the "Form" class' header file as follows:
@interface Form : NSObject <NSCopying> {
Cube *cube[MAX_CUBE];
}
The following are the "Cube" class' variables as defined in its header file:
@interface Cube : NSObject <NSCopying> {
double size;
double positionX;
double positionY;
double positionZ;
}
...and the corresponding accessors in the implementation (.m) file:
- (double) size {
return size;
}
- (void) setSize: (double) newSize {
size = newSize;
}
- (double) positionX {
return positionX;
}
- (void) setPositionX: (double) newPositionX {
positionX = newPositionX;
}
- (double) positionY {
return positionY;
}
- (void) setPositionY: (double) newPositionY {
positionY = newPositionY;
}
- (double) positionZ {
return positionZ;
}
- (void) setPositionZ: (double) newPositionZ {
positionZ = newPositionZ;
}
I would like to avoid using an NSMutableArray o NSArray as I plan to port this part of the project's code to non-Cocoa platforms later on.
I've spent the last couple of hours searching for the correct way to do this. Is there "a right way" to do this using C-Style arrays and Objective-C accessors?