2012-10-30 78 views
-1

我需要填写dae_prim *array_prim;其中dae_prim是我创建的类。Objective-C:指针运算

我想使用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 
+0

一些代码会有所帮助。 – Eimantas

+2

很可能你没有包含完全定义'dae_prim'的头文件。但是你没有提供太多的信息。 (如果你正在存储Objective-C对象,你应该使用简单的C结构将数据传递给OpenGL。) –

+0

用更多的代码编辑我的问题 @JeremyRoman不,头可以,我可以使用所有类及其成员 – IggY

回答

2

你需要使用一个双指针作为mesh-> 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]; 

干杯。