我有代码:
class Point3D{
protected:
float x;
float y;
float z;
public:
Point3D(){x=0; y=0; z=0;}
Point3D(const Point3D & point){x = point.x; y = point.y; z = point.z;}
Point3D(float _x,float _y,float _z){x = _x; y = _y; z = _z;}
}
class Vector3D{
protected:
Point3D start;
Point3D end;
public:
...
Point3D getSizes(){
return Point3D(end-start);
}
}
我想为将采用向量的 Point3D 创建和 operator+:
Point3D & operator+(const Vector3D &vector){
Point3D temp;
temp.x = x + vector.getSizes().x;
temp.y = y + vector.getSizes().y;
temp.z = z + vector.getSizes().z;
return temp;
}
但是当我将该操作放在 Point3D 类声明的旁边时,我得到了错误,因为我没有在这里声明 Vector3D。而且我不能在 Point3D 之前移动 Vector3D 声明,因为它使用 Point3D。