无法在块内引用具有可变修改类型的声明 [英] Cannot refer to declaration with a variably modified type inside block
本文介绍了无法在块内引用具有可变修改类型的声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码段,我遇到了上述错误.
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);
.
.
.
});
}
});
照相机实际上是C型结构,并且错误是由照相机阵列引起的.有人请帮助我摆脱这个问题.
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.
推荐答案
您的相机位于堆栈中,而Objective-C在带有不支持引用计数的变量的块中表现不佳.尝试在NSObject中移动此数组:
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);
.
.
.
});
}
});
这篇关于无法在块内引用具有可变修改类型的声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文