繁体   English   中英

Objective-C:指针算法

[英]Objective-C: pointer arithmetic

我需要填写一个dae_prim *array_prim; 其中dae_prim是我创建的类。

我想使用C样式,因为我会将所有这些数据传递给OpenGL。

当我尝试创建: mesh->array_prim[i] = mysexyprim它失败并显示“下标需要接口的大小”。

我想我理解问题了(Obj-C要我使用NSArray),但是如何绕开呢?

更多代码

class meshes:
@public:
   dae_prim *prims;
   int primcount;

model->meshes->prims = malloc(sizeof(dae_prims*) * model->meshes->primcount);
dae_prim *prims = [[dae_prim alloc]init];
model->meshes->prims[1] = prims; //here is the problem

您需要对meshes-> prims使用双指针,因为您需要一个指针数组。

class meshes:
@public:
   dae_prim **prims; /* a C array of objects pointers */
   int primcount;

model->meshes->prims = malloc(sizeof(dae_prims*) * model->meshes->primcount);
model->meshes->prims[1] = [[dae_prim alloc]init];

干杯。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM