(iPhone)仅仅是为了声明和设置一个愚蠢的变量而让我抓狂。代码如下:
const GLfloat zNear = 0.01, zFar = 1000.0, fieldOfView = 60.0;
GLfloat size;
size = zNear * tanf(DEGREES_TO_RADIANS*fieldOfView / 2.0));给我的错误是“‘size’类型冲突”。
如果我写成这样:
const GLfloat zNear = 0.01, zFar = 1000.0, fieldOfView = 60.0;
GLfloat size = zNear * tanf(DEGREES_TO_RADIANS*fieldOfView / 2.0));我得到一个错误,"Initializer元素不是常量“。
真正奇怪的是,这段代码在一个方法中运行得很好。我把它移出了方法,现在它失败了。这里发生了什么事?
发布于 2011-04-07 05:36:17
在全局作用域处理时,只能将语句分配给常量文字。
// At global scope
int a = 10 ; // fine
int b = a ; // Not allowed
b = a ; // Not allowed
b = 100 ; // fine
const int aa = 10 ; // fine
const int bb ;
bb = aa ; // Not allowed解决方案是#define。试试这个-
#define zNear 0.01
#define zFar 1000.0
#define fieldOfView 60.0
GLfloat size;
size = zNear * tanf(DEGREES_TO_RADIANS*fieldOfView / 2.0));https://stackoverflow.com/questions/5573129
复制相似问题