Original Post
Hello; Here is my code for a simple 3-float-vector class this works ok in my VisualStudio, but in DevC++ it says no match for 'operator+' in 'posicao + cVETOR3D::operator*(float)' candidates are: cVETOR3D cVETOR3D::operator+(cVETOR3D&) So i think that i cannot have a method that use a reference for a returning instance (the method cVETOR3D*float return a local intance of cVETOR3D)...how can i do that work in DevC++? Thanks!
class cVETOR3D
{
public:
cVETOR3D():x(0),y(0),z(0){}
cVETOR3D(float xx,float yy,float zz):x(xx),y(yy),z(zz){}
~cVETOR3D();
//operações
void operator =(cVETOR3D &vet)
{
x = vet.x;
y = vet.y;
z = vet.z;
}
void operator +=(cVETOR3D &vet)
{
x+=vet.x;
y+=vet.y;
z+=vet.z;
}
void operator -=(cVETOR3D &vet)
{
x-=vet.x;
y-=vet.y;
z-=vet.z;
}
cVETOR3D operator +(cVETOR3D &vet)
{
cVETOR3D v;
v.x = x+vet.x;
v.y = y+vet.y;
v.z = z+vet.z;
return v;
}
cVETOR3D operator -(cVETOR3D &vet)
{
cVETOR3D v;
v.x = x-vet.x;
v.y = y-vet.y;
v.z = z-vet.z;
return v;
}
cVETOR3D operator*(float v)
{
return cVETOR3D(x*v,y*v,z*v);
}
cVETOR3D operator/(float v)
{
return cVETOR3D(x/v,y/v,z/v);
}
cVETOR3D operator*=(float v)
{
x*=v;
y*=v;
z*=v;
}
cVETOR3D operator/=(float v)
{
x/=v;
y/=v;
z/=v;
}
cVETOR3D operator-()
{
cVETOR3D v;
v.x = -x;
v.y = -y;
v.z = -z;
return v;
}
//retorna a magnitude do vetor
float Magnitude()
{
return sqrtf(x*x+y*y+z*z);
}
//transforma o vetor para comprimento = 1
void Normalizar()
{
float mag = Magnitude();
//evita divisoes por 0
if (mag == 0)
mag = 1;
x/=mag;
y/=mag;
z/=mag;
}
//retorna o produto interno entre 2 vetores
float Dot(cVETOR3D &vet)
{
return x*vet.x+y*vet.y+z*vet.z;
}
//atribui um vetor resultante do produto cruzado entre v1 e v2
void Cross(cVETOR3D &v1,cVETOR3D &v2)
{
x = v1.y * v2.z - v1.z*v2.y;
y = v1.z * v2.x - v1.x*v2.z;
z = v1.x * v2.y - v1.y*v2.x;
}
//reflete o vetor pela normal n
void Refletir(cVETOR3D &n)
{
cVETOR3D vn = n * (n.Dot(*this));
cVETOR3D vt = *this - vn;
x = vt.x - vn.x;
y = vt.y - vn.y;
z = vt.z - vn.z;
}
float x,y,z;
};
////////////////
//main code ...
////////////////
...
cVETOR3D posicao;
cVETOR3D direcao;
float velocidade;
posicao = posicao+direcao*velocidade;