| 编程中国 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛
全能ASP/PHP/ASP.NET主机,支持月付专业 MSSQL 数据库空间,支持月付专业 MySQL 数据库空间,支持月付买域名,送MP3、MP4
高端软件开发 = 年薪十万不是梦赛孚耐:软件保护加密专家身份认证令牌USB KEY买空间,免费送域名(厦门中资源)
共有 1987 人关注过本帖
标题:[讨论]为何出现“illegal use of this type as an expression”这种编译错误 ...
收藏  订阅  推荐  打印 
luckchina
Rank: 1
等级:新手上路
帖子:16
积分:260
注册:2006-4-20
[讨论]为何出现“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: 4
等级:高级会员
威望:8
帖子:850
积分:8600
注册:2006-11-13

不是已经说得很清楚了吗

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

hey,di va la
2006-12-11 19:02
luckchina
Rank: 1
等级:新手上路
帖子:16
积分:260
注册:2006-4-20

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
积分:260
注册:2006-4-20

棘手,在线等。
2006-12-11 19:41
yingbinchina
Rank: 1
等级:新手上路
帖子:1
积分:110
注册:2007-2-2
我也遇到相同的问题

你好! 我在运行Opengl超级宝典第三版的示例程序时,也遇到这样的问题,不知道你是如何解决的?
2007-2-2 10:31
wdxwzx
Rank: 1
等级:新手上路
帖子:2
积分:122
注册:2008-8-9

me too.
2008-8-16 20:20
wdxwzx
Rank: 1
等级:新手上路
帖子:2
积分:122
注册:2008-8-9

把FrameMath.c文件里所有的GLTVector3 vNewVect;改为全局数组,编译就通过!!!!因为 FrameMath.c文件里有多重定义.
2008-8-16 20:32
关于我们 | 广告合作 | 编程中国 | 清除Cookies | Archiver | WAP | TOP

编程中国 版权所有,并保留所有权利。鲁ICP备08000592号
Powered by Discuz, Processed in 0.053494 second(s), 9 queries.
Copyright©2004-2008, BCCN.NET, All Rights Reserved