class vec_2d
{
public:
union {
struct{float x,y;};
float v[2];
};
vec_2d() {};
vec_2d(const float f) : x(f),y(f) {}
vec_2d(const float fx,const float fy) : x(fx),y(fy) {}
void assign(const float X,const float Y) {x=X;y=Y;}
float len();
float dot(const vec_2d&);
vec_2d normalize();
operator float *() {return &x;}
operator const float *() const {return &x;}
void operator += (const vec_2d& rhs) { x += rhs.x; y += rhs.y; }
void operator -= (const vec_2d& rhs) { x -= rhs.x; y -= rhs.y; }
void operator *= (const vec_2d& rhs) { x *= rhs.x; y *= rhs.y; }
void operator *= (const float rhs) { x *= rhs; y *= rhs; }
void operator /= (const vec_2d& rhs) { x /= rhs.x; y /= rhs.y; }
void operator /= (const float rhs) { x /= rhs; y /= rhs; }
vec_2d operator + (const vec_2d& rhs);
vec_2d operator + (const float rhs);
vec_2d operator - (const vec_2d& rhs);
vec_2d operator - (const float rhs);
vec_2d operator - ();
vec_2d operator * (const vec_2d& rhs);
friend vec_2d operator * (const float lhs, const vec_2d& rhs);
vec_2d operator * (const float rhs);
vec_2d operator / (const vec_2d& rhs);
vec_2d operator / (const float rhs);
bool operator == (const vec_2d& rhs);
bool operator != (const vec_2d& rhs);
};
Перегрузка операторов,не пойму ошибку
Код:
и собственно реализация
Код:
vec_2d vec_2d::operator + (const vec_2d& rhs) {
return vec_2d(x + rhs.x, y + rhs.y);
}
vec_2d vec_2d::operator + (const float rhs) {
return vec_2d(x + rhs, y + rhs);
}
vec_2d vec_2d::operator - (const vec_2d& rhs) {
return vec_2d(x - rhs.x, y - rhs.y);
}
vec_2d vec_2d::operator - (const float rhs) {
return vec_2d(x - rhs, y - rhs);
}
vec_2d vec_2d::operator - () {
return vec_2d(-x,-y);
}
vec_2d vec_2d::operator * (const vec_2d& rhs) {
return vec_2d(x * rhs.x, y * rhs.y);
}
vec_2d operator * (const float lhs, const vec_2d& rhs) {
return vec_2d(lhs * rhs.x, lhs * rhs.y);
}
vec_2d vec_2d::operator * (const float rhs) {
return vec_2d(x * rhs, y * rhs);
}
vec_2d vec_2d::operator / (const vec_2d& rhs) {
return vec_2d(x / rhs.x, y / rhs.y);
}
vec_2d vec_2d::operator / (const float rhs) {
return vec_2d(x / rhs, y / rhs);
}
bool vec_2d::operator == (const vec_2d& rhs) {
return (x == rhs.x && y == rhs.y);
}
bool vec_2d::operator != (const vec_2d& rhs) {
return (x != rhs.x || y != rhs.y);
}
float vec_2d::len() {
return sqrtf(x * x + y * y);
}
float vec_2d::dot(const vec_2d& v) {
return x * v.x + y * v.y;
}
vec_2d vec_2d::normalize() {
float il = 1.0f / sqrtf(x * x + y * y);
return vec_2d(x * il,y * il);
}
return vec_2d(x + rhs.x, y + rhs.y);
}
vec_2d vec_2d::operator + (const float rhs) {
return vec_2d(x + rhs, y + rhs);
}
vec_2d vec_2d::operator - (const vec_2d& rhs) {
return vec_2d(x - rhs.x, y - rhs.y);
}
vec_2d vec_2d::operator - (const float rhs) {
return vec_2d(x - rhs, y - rhs);
}
vec_2d vec_2d::operator - () {
return vec_2d(-x,-y);
}
vec_2d vec_2d::operator * (const vec_2d& rhs) {
return vec_2d(x * rhs.x, y * rhs.y);
}
vec_2d operator * (const float lhs, const vec_2d& rhs) {
return vec_2d(lhs * rhs.x, lhs * rhs.y);
}
vec_2d vec_2d::operator * (const float rhs) {
return vec_2d(x * rhs, y * rhs);
}
vec_2d vec_2d::operator / (const vec_2d& rhs) {
return vec_2d(x / rhs.x, y / rhs.y);
}
vec_2d vec_2d::operator / (const float rhs) {
return vec_2d(x / rhs, y / rhs);
}
bool vec_2d::operator == (const vec_2d& rhs) {
return (x == rhs.x && y == rhs.y);
}
bool vec_2d::operator != (const vec_2d& rhs) {
return (x != rhs.x || y != rhs.y);
}
float vec_2d::len() {
return sqrtf(x * x + y * y);
}
float vec_2d::dot(const vec_2d& v) {
return x * v.x + y * v.y;
}
vec_2d vec_2d::normalize() {
float il = 1.0f / sqrtf(x * x + y * y);
return vec_2d(x * il,y * il);
}
потом в коде встречается выражение вида
Код:
vec_2d v= v_begin - v_end; //v_begin,v_end - определены ранее
и вот такая байда вылазит:
Код:
1>c:\zulus_engine\zulus_engine\matrix.cpp(225) : error C2678: binary '*' : no operator found which takes a left-hand operand of type 'const math::vec_3d' (or there is no acceptable conversion)
1> c:\zulus_engine\zulus_engine\vector.h(40): could be 'math::vec_2d math::operator *(const float,const math::vec_2d &)'
1> c:\zulus_engine\zulus_engine\vector.h(82): or 'math::vec_3d math::operator *(const float,const math::vec_3d &)' [found using argument-dependent lookup]
1> c:\zulus_engine\zulus_engine\vector.h(131): or 'math::vec_4d math::operator *(const float,const math::vec_4d &)'
1> c:\zulus_engine\zulus_engine\matrix.h(167): or 'math::mat4x4 math::operator *(const math::mat4x4 &,const math::mat4x4 &)'
1> c:\zulus_engine\zulus_engine\matrix.h(170): or 'const math::vec_3d math::operator *(const math::mat4x4 &,const math::vec_3d &)'
1> c:\zulus_engine\zulus_engine\matrix.h(177): or 'const math::vec_3d math::operator *(const math::vec_3d &,const math::mat4x4 &)'
1> c:\zulus_engine\zulus_engine\matrix.h(183): or 'const math::vec_4d math::operator *(const math::mat4x4 &,const math::vec_4d &)'
1> c:\zulus_engine\zulus_engine\matrix.h(191): or 'const math::vec_4d math::operator *(const math::vec_4d &,const math::mat4x4 &)'
1> c:\zulus_engine\zulus_engine\matrix.h(197): or 'math::lineSeg3 math::operator *(const math::lineSeg3 &,const math::mat4x4 &)'
1> c:\zulus_engine\zulus_engine\matrix.h(202): or 'math::lineSeg3 math::operator *(const math::mat4x4 &,const math::lineSeg3 &)'
1> c:\zulus_engine\zulus_engine\vector.h(81): or 'math::vec_3d math::vec_3d::operator *(const math::vec_3d &)'
1> c:\zulus_engine\zulus_engine\vector.h(83): or 'math::vec_3d math::vec_3d::operator *(const float)'
1> c:\zulus_engine\zulus_engine\vector.h(82): or 'math::vec_3d math::operator *(const float,const math::vec_3d &)' [found using argument-dependent lookup]
1> while trying to match the argument list '(const math::vec_3d, math::vec_3d)'
1> c:\zulus_engine\zulus_engine\vector.h(40): could be 'math::vec_2d math::operator *(const float,const math::vec_2d &)'
1> c:\zulus_engine\zulus_engine\vector.h(82): or 'math::vec_3d math::operator *(const float,const math::vec_3d &)' [found using argument-dependent lookup]
1> c:\zulus_engine\zulus_engine\vector.h(131): or 'math::vec_4d math::operator *(const float,const math::vec_4d &)'
1> c:\zulus_engine\zulus_engine\matrix.h(167): or 'math::mat4x4 math::operator *(const math::mat4x4 &,const math::mat4x4 &)'
1> c:\zulus_engine\zulus_engine\matrix.h(170): or 'const math::vec_3d math::operator *(const math::mat4x4 &,const math::vec_3d &)'
1> c:\zulus_engine\zulus_engine\matrix.h(177): or 'const math::vec_3d math::operator *(const math::vec_3d &,const math::mat4x4 &)'
1> c:\zulus_engine\zulus_engine\matrix.h(183): or 'const math::vec_4d math::operator *(const math::mat4x4 &,const math::vec_4d &)'
1> c:\zulus_engine\zulus_engine\matrix.h(191): or 'const math::vec_4d math::operator *(const math::vec_4d &,const math::mat4x4 &)'
1> c:\zulus_engine\zulus_engine\matrix.h(197): or 'math::lineSeg3 math::operator *(const math::lineSeg3 &,const math::mat4x4 &)'
1> c:\zulus_engine\zulus_engine\matrix.h(202): or 'math::lineSeg3 math::operator *(const math::mat4x4 &,const math::lineSeg3 &)'
1> c:\zulus_engine\zulus_engine\vector.h(81): or 'math::vec_3d math::vec_3d::operator *(const math::vec_3d &)'
1> c:\zulus_engine\zulus_engine\vector.h(83): or 'math::vec_3d math::vec_3d::operator *(const float)'
1> c:\zulus_engine\zulus_engine\vector.h(82): or 'math::vec_3d math::operator *(const float,const math::vec_3d &)' [found using argument-dependent lookup]
1> while trying to match the argument list '(const math::vec_3d, math::vec_3d)'
прошу прощения за портянку...Может кто подскажет???