首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

inline函数有关问题

2012-03-27 
inline函数问题#ifndef_TEST0_H_#define_TEST0_H_typedef struct _POINT3{float x, y, z_POINT3() {}_POI

inline函数问题
#ifndef_TEST0_H_
#define_TEST0_H_
typedef struct _POINT3
{
float x, y, z;

_POINT3() {}
_POINT3( float X, float Y, float Z ) { x = X; y = Y; z = Z; }
inline void operator += ( _POINT3 P ) { x += P.x; y += P.y; z += P.z; }
inline void operator -= ( _POINT3 P ) { x -= P.x; y -= P.y; z -= P.z; }
inline void operator += ( float f ) { x += f; y += f; z += f; }
inline void operator -= ( float f ) { x -= f; y -= f; z -= f; }
inline void operator *= ( float f ) { x *= f; y *= f; z *= f; }
inline void operator /= ( float f ) { x /= f; y /= f; z /= f; }
}POINT3, *LPPOINT3, VECTOR3, *LPVECTOR3;
#endif


VECTOR3 Normal0 = VECTOR3( ( sHeight[0].bNormalX / 255.0f ) * 2 - 1.0f,
( sHeight[0].bNormalY / 255.0f ) * 2 - 1.0f,
g_fNormalTable[sHeight[0].bNormalX][sHeight[0].bNormalY] ) ;
VECTOR3 Normal1 = VECTOR3( ( sHeight[1].bNormalX / 255.0f ) * 2 - 1.0f,
( sHeight[1].bNormalY / 255.0f ) * 2 - 1.0f,
g_fNormalTable[sHeight[1].bNormalX][sHeight[1].bNormalY] ) ;
VECTOR3 Normal2 = VECTOR3( ( sHeight[2].bNormalX / 255.0f ) * 2 - 1.0f,
( sHeight[2].bNormalY / 255.0f ) * 2 - 1.0f,
g_fNormalTable[sHeight[2].bNormalX][sHeight[2].bNormalY] ) ;
VECTOR3 Normal3 = VECTOR3( ( sHeight[3].bNormalX / 255.0f ) * 2 - 1.0f,
( sHeight[3].bNormalY / 255.0f ) * 2 - 1.0f,
g_fNormalTable[sHeight[3].bNormalX][sHeight[3].bNormalY] ) ;


error C2676: binary '*' : 'VECTOR3' does not define this operator or a conversion to a type acceptable to the predefined operator
1>e:\visual studio 2008\projects\test0\test0\test0.cpp(140) : error C2676: binary '*' : 'VECTOR3' does not define this operator or a conversion to a type acceptable to the predefined operator
1>e:\visual studio 2008\projects\test0\test0\test0.cpp(141) : error C2676: binary '*' : 'VECTOR3' does not define this operator or a conversion to a type acceptable to the predefined operator
1>e:\visual studio 2008\projects\test0\test0\test0.cpp(141) : error C2676: binary '*' : 'VECTOR3' does not define this operator or a conversion to a type acceptable to the predefined operator
1>e:\visual studio 2008\projects\test0\test0\test0.cpp(142) : error C2676: binary '*' : 'VECTOR3' does not define this operator or a conversion to a type acceptable to the predefined operator
1>e:\visual studio 2008\projects\test0\test0\test0.cpp(142) : error C2676: binary '*' : 'VECTOR3' does not define this operator or a conversion to a type acceptable to the predefined operator




[解决办法]
你所有的操作符都返回 void, 当然不能进行组合运算了.

都改成类似下面这样的:

inline _POINT3& operator += ( float f ) { x += f; y += f; z += f; return *this; }

热点排行