| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 10065 人关注过本帖
标题:[讨论]为何出现“illegal use of this type as an expression”这种编译错误 ...
只看楼主 加入收藏
luckchina
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2006-4-20
收藏
 问题点数:0 回复次数:6 
[讨论]为何出现“illegal use of this type as an expression”这种编译错误?

//////////////////////////////////////////////////////////
// Rotate a frame around it's local X axis
void gltRotateFrameLocalX(GLTFrame *pFrame, GLfloat fAngle)
{
GLTMatrix mRotation;
GLTVector3 vCross;

gltVectorCrossProduct(vCross, pFrame->vUp, pFrame->vForward);
gltRotationMatrix(fAngle, vCross[0], vCross[1], vCross[2], mRotation);

GLTVector3 vNewVect;
// Inline 3x3 matrix multiply for rotation only
vNewVect[0] = mRotation[0] * pFrame->vForward[0] + mRotation[4] * pFrame->vForward[1] + mRotation[8] * pFrame->vForward[2];
vNewVect[1] = mRotation[1] * pFrame->vForward[0] + mRotation[5] * pFrame->vForward[1] + mRotation[9] * pFrame->vForward[2];
vNewVect[2] = mRotation[2] * pFrame->vForward[0] + mRotation[6] * pFrame->vForward[1] + mRotation[10] * pFrame->vForward[2];
memcpy(pFrame->vForward, vNewVect, sizeof(GLfloat)*3);

// Update pointing up vector
vNewVect[0] = mRotation[0] * pFrame->vUp[0] + mRotation[4] * pFrame->vUp[1] + mRotation[8] * pFrame->vUp[2];
vNewVect[1] = mRotation[1] * pFrame->vUp[0] + mRotation[5] * pFrame->vUp[1] + mRotation[9] * pFrame->vUp[2];
vNewVect[2] = mRotation[2] * pFrame->vUp[0] + mRotation[6] * pFrame->vUp[1] + mRotation[10] * pFrame->vUp[2];
memcpy(pFrame->vUp, vNewVect, sizeof(GLfloat) * 3);
}

/////////////////////////////////////////////////////////////

以上代码是一个围绕X轴旋转的函数,其中GLTVector3是OpenGL中定义的类型,相当于C++中的float类型。GLTVector3定义的原型如下:
typedef GLfloat GLTVector3[3]; // Three component floating point vector

位于(\Microsoft Visual Studio\VC98\Include\GL\GLTools.h)GLTools.h代码的51行。

编译错误如下:
E:\OpenGL\Windows\Common\FrameMath.c(178) : error C2275: 'GLTVector3' : illegal use of this type as an expression
D:\Program Files\Microsoft Visual Studio\VC98\INCLUDE\gl\gltools.h(51) : see declaration of 'GLTVector3'
E:\OpenGL\Windows\Common\FrameMath.c(178) : error C2146: syntax error : missing ';' before identifier 'vNewVect'
E:\OpenGL\Windows\Common\FrameMath.c(178) : error C2065: 'vNewVect' : undeclared identifier
E:\OpenGL\Windows\Common\FrameMath.c(180) : error C2109: subscript requires array or pointer type
E:\OpenGL\Windows\Common\FrameMath.c(180) : warning C4244: '=' : conversion from 'float ' to 'int ', possible loss of data
E:\OpenGL\Windows\Common\FrameMath.c(180) : error C2106: '=' : left operand must be l-value

其中错误1:E:\OpenGL\Windows\Common\FrameMath.c(178) : error C2275: 'GLTVector3' : illegal use of this type as an expression
非法使用该类型作为一个表达式。
请问如何解决该问题?????

搜索更多相关主题的帖子: expression 编译 illegal use type 
2006-12-11 18:47
一二三四五
Rank: 3Rank: 3
等 级:新手上路
威 望:8
帖 子:856
专家分:0
注 册:2006-11-13
收藏
得分:0 
不是已经说得很清楚了吗

有没有定义,它是不是一种异常

hey,di va la
2006-12-11 19:02
luckchina
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2006-4-20
收藏
得分:0 
GLTVector3类型已经在GLTools.h中定义了,它表示一个存储三维坐标的数组。
我作如下定义:
GLTVector3 vNewVect;
编译就出现了这个错误:E:\OpenGL\Windows\Common\FrameMath.c(178) : error C2275: 'GLTVector3' : illegal use of this type as an expression
2006-12-11 19:09
luckchina
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2006-4-20
收藏
得分:0 
棘手,在线等。
2006-12-11 19:41
yingbinchina
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2007-2-2
收藏
得分:0 
我也遇到相同的问题
你好! 我在运行Opengl超级宝典第三版的示例程序时,也遇到这样的问题,不知道你是如何解决的?
2007-02-02 10:31
wdxwzx
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2008-8-9
收藏
得分:0 
me too.
2008-08-16 20:20
wdxwzx
Rank: 1
等 级:新手上路
帖 子:2
专家分:0
注 册:2008-8-9
收藏
得分:0 
把FrameMath.c文件里所有的GLTVector3 vNewVect;改为全局数组,编译就通过!!!!因为 FrameMath.c文件里有多重定义.
2008-08-16 20:32
快速回复:[讨论]为何出现“illegal use of this type as an expression”这种编 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015569 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved