面膜漫画式软文范例:VC编译时为何会出现只要的错误!!

来源:百度文库 编辑:中科新闻网 时间:2024/04/29 05:14:26
我编写了这样一个类的头文件
#include "TVector.h"

class CSmallSphere
{
public:
CSmallSphere();
virtual ~CSmallSphere();
bool TestIntersionCylinder(const Cylinder&, const CTVector&, const CTVector&, double&, CTVector&, CTVector&);
bool TestIntersionPlane(const Plane&, const CTVector&, const CTVector&, double&, CTVector&);

……其他成员变量略
};
其中两个成员函数在其cpp文件里这样实现
bool CSmallSphere::TestIntersionPlane(const Plane &plane, const CTVector &position, const CTVector &direction, double &lamda, CTVector &pNormal)
{
double DotProduct=direction.dot(plane._Normal);
double l2;

//determine if ray paralle to plane
if ((DotProduct<ZERO)&&(DotProduct>-ZERO))
return false;

l2=(plane._Normal.dot(plane._Position-position))/DotProduct;

if (l2<-ZERO)
return false;

pNormal=plane._Normal;
lamda=l2;
return true;

}

bool CSmallSphere::TestIntersionCylinder(const Cylinder &cylinder, const CTVector &position, const CTVector &direction, double &lamda, CTVector &pNormal, CTVector &newposition)
{
CTVector RC;
double d;
double t,s;
CTVector n,D,O;
double ln;
double in,out;

CTVector::subtract(position, cylinder._Position, RC);
CTVector::cross(direction, cylinder._Axis, n);

ln=n.mag();

if ( (ln<ZERO)&&(ln>-ZERO) ) return 0;

n.unit();

d= fabs( RC.dot(n) );

if (d<=cylinder._Radius)
{
CTVector::cross(RC,cylinder._Axis,O);
t= - O.dot(n)/ln;
CTVector::cross(n,cylinder._Axis,O);
O.unit();
s= fabs( sqrt(cylinder._Radius*cylinder._Radius - d*d) / direction.dot(O) );

in=t-s;
out=t+s;

if (in<-ZERO){
if (out<-ZERO)
return 0;
else
lamda=out;
}
else if (out<-ZERO) {
lamda=in;
}
else if
(in<out) lamda=in;
else
lamda=out;

newposition=position+direction*lamda;
CTVector HB=newposition-cylinder._Position;
pNormal=HB - cylinder._Axis*(HB.dot(cylinder._Axis));
pNormal.unit();

return true;
}

return false;

}

结果编译时出现以下几个错误
smallsphere.h(18) : error C2143: syntax error : missing ',' before '&'
smallsphere.h(18) : error C2059: syntax error : '&'
smallsphere.h(19) : error C2143: syntax error : missing ',' before '&'
error C2059: syntax error : '&'
error C2511: 'TestIntersionPlane' : overloaded member function 'int (const struct CSmallSphere::Plane &,const class CTVector &,const class CTVector &,double &,class CTVector &)' not found in 'CSmallSphere'
smallsphere.h(14) : see declaration of 'CSmallSphere'
SmallSphere.cpp(79) : error C2511: 'TestIntersionCylinder' : overloaded member function 'int (const struct CSmallSphere::Cylinder &,const class CTVector &,const class CTVector &,double &,class CTVector &,class CTVector &)' not found in 'CSmallSphere'
smallsphere.h(14) : see declaration of 'CSmallSphere'
请问这是怎么回事,我弄不懂了。
谢谢!

我想你前面的三个错导致了那两个函数没有被成功定义,所有才有后面的错。

或者你的确定义了两对个返回型为int和bool的函数,但int型的没声明。

建议函数声明改成这样试试:
bool TestIntersionPlane(const Plane &plane, const CTVector &position, const CTVector &direction, double &lamda, CTVector &pNormal);

因为细节太少,也只能猜测一下了。Good Luck!