I've made a vector class which contain the x, y, and z coordinates. The thing is i wanted to compare 2 vectors. This is my vector class
Code:
class vect3
{
public:
double x, y, z;
vect3()
{
x=0; y=0; z=0;
}
vect3(double xc, double yc, double zc)
{
x = xc;
y = yc;
z = zc;
}
vect3& operator=(vect3 &v)
{
x = v.x;
y = v.y;
z = v.z;
return *this;
}
- So i've been able to give the vector's x, y, z values using operator. But then when i put this compare operator in:
Code:
//compare vector
vect3& operator ==(vect3 v)
{
if(( x == v.x) &&
( y == v.y) &&
( z == v.z))
return v;
}
vect3& operator <=(vect3 &v)
{
if(( x <= v.x)&&
( y <= v.y)&&
( z <= v.z))
return v;
}
vect3& operator >=(vect3 &v)
{
if((x >= v.x) &&
(y >= v.y) &&
(z >= v.z))
return v;
}
Run the operator...
Code:
vect3 v1, v2;
if(v1 == v2)
// statement is true;
and get this error
Code:
error C2451: conditional expression of type 'class vect3' is illegal
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
So can anyone help me and point out what the problem is. Thanks