Cannot refer to declaration with a variably modified type inside block [duplicate]

被刻印的时光 ゝ 提交于 2019-12-24 01:44:44

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!