Objective C LValue 需要作为一元 '&'操作数
在我的代码中,当我尝试获取指向我的类属性的指针时,出现此错误。
(我用 Python 编写了一个小型 *.OBJ 文件转换器,丢弃了法线)
代码:
//line: line of text
const char *str = [line UTF8String];
Point3D *p1, *p2, *p3;
p1 = [Point3D makeX:0 Y:0 Z:0];
p2 = [Point3D makeX:0 Y:0 Z:0];
p3 = [Point3D makeX:0 Y:0 Z:0];
sscanf(str, "t %f,%f,%f %f,%f,%f %f,%f,%f",(&[p1 x]),&([p1 y]),&([p1 z]),&([p2 x]),&([p2 y]),&([p2 z]),&([p3 x]),&([p3 y]),&([p3 z]));
Triangle3D *tri = [Triangle3D make:p1 p2:p2 p3:p3];
In my code, I get this error when I try to get a pointer to my class property.
(I wrote a small *.OBJ file translator in Python, discarding the normals)
CODE:
//line: line of text
const char *str = [line UTF8String];
Point3D *p1, *p2, *p3;
p1 = [Point3D makeX:0 Y:0 Z:0];
p2 = [Point3D makeX:0 Y:0 Z:0];
p3 = [Point3D makeX:0 Y:0 Z:0];
sscanf(str, "t %f,%f,%f %f,%f,%f %f,%f,%f",(&[p1 x]),&([p1 y]),&([p1 z]),&([p2 x]),&([p2 y]),&([p2 z]),&([p3 x]),&([p3 y]),&([p3 z]));
Triangle3D *tri = [Triangle3D make:p1 p2:p2 p3:p3];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
x
、y
、z
是消息访问器吗?大概吧。然后它们返回值的副本(因为 Objective-C 没有引用的概念),并且您将指向临时变量的指针传递给 sscanf 函数,从而产生错误。您应该使用局部变量从 sscanf 函数获取值。像这样的东西:
Are the
x
,y
,z
messages accessors ? I guess so. Then they are returning copy of the values (since Objective-C does not have the notion of references), and you are passing to thesscanf
function pointers to temporaries, and thus the error.You should use local variables to get the values from the
sscanf
function. Something like that: