问题
This is the snippet of my code and i am getting the above mentioned error.
dispatch_async(background_thread, ^{
cameras camera[10];
.
.
for(int i=0; i<ncam; i++) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0),^{
iPoint subPoints[10];
subPoints[0].x = camera[i].x + ((int)camera[i].mindist)*cos(camera[i].dir + (camera[i].angle)/2);
.
.
.
});
}
});
cameras is actually a C-type structure and the error is with camera array. Someone please help me how to get rid off with this problem.
回答1:
Yours cameras located in stack, and objective-c work badly in blocks with variables that doesn't support reference counting. Try move this array inside NSObject:
@interface TenCameras : NSObject
{
@public
cameras camera[10];
}
@end
Then yours code will be something like that:
dispatch_async(background_thread, ^{
TenCameras tenCameras;
.
.
for(int i=0; i<ncam; i++) {
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT,0),^{
iPoint subPoints[10];
subPoints[0].x = tenCameras->camera[i].x + ((int)tenCameras->camera[i].mindist)*cos(tenCameras->camera[i].dir + (tenCameras->camera[i].angle)/2);
.
.
.
});
}
});
来源:https://stackoverflow.com/questions/22658656/cannot-refer-to-declaration-with-a-variably-modified-type-inside-block