我有两个结构,一个是基本结构,position_3d。另一位是雷。
typedef struct{
float x,y,z;
} position_3d;
typedef struct{
vector_3d direction;
position_3d startPosition;
} ray;
我已经实现了一个返回position_3d结构的函数
position_3d getIntersectionPosition(ray r, sphere s){
position_3d pos;
//some code
pos.x = r.startPosition.x + t*r.direction.x;
pos.y = r.startPosition.y + t*r.direction.y;
pos.z = r.startPosition.z + t*r.direction.z;
return pos;
}
当我打电话时
position_3d pos = getIntersectionPosition(r, s);
我收到此错误:无效的初始值设定项。我正在使用海湾合作委员会。 编译命令为 gcc prog.c -o prog.out -lm -lGL -lGLU -lglut
我现在真的陷入困境了!有人可以帮忙吗?
最佳答案
是线
position_3d pos = getIntersectionPosition(r, s);
在文件范围(那么这是一个错误,因为初始化器不是常量)或 block 范围(那么它应该工作)?
关于c - 结构体初始化错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10566790/