我正在查看一些代码,我想知道友元运算符在这个类头文件中做了什么。
这是否只需要说“当我使用此运算符并且两个输入都是 CSegment3D 类型时,我以函数实现中定义的方式对它们进行操作”?
class CSegment3D : public CObject
{
public:
CSegment3D& operator*=(const double& factor);// multiply by a scalar factor & assign
CSegment3D& operator/=(const double& factor);// divide by a scalar factor & assign
CSegment3D& operator+=(const CSegment3D& other);// vector addition
CSegment3D& operator-=(const CSegment3D& other);// vector subtraction
friend CSegment3D GetMidpoint(const CSegment3D& ptA, const CSegment3D& ptB);
friend CSegment3D GetNormal( CSegment3D *pSeg1, CSegment3D *pSeg2, CSegment3D *pSeg3 ); // Return a point normal to the surface defines by the tree point passed in.
friend double operator*(const CSegment3D& vectorA, const CSegment3D& vectorB); // dot product
friend CSegment3D operator*(const double& factor, const CSegment3D& vectorA); // multiply by a scalar
friend CSegment3D operator/(const CSegment3D& vectorA, const double& factor); // divide by a scalar
friend CSegment3D operator+(const CSegment3D& vectorA, const CSegment3D& vectorB);// vector addition
friend CSegment3D operator-(const CSegment3D& vectorA, const CSegment3D& vectorB );// vector subtraction
friend CSegment3D operator^(const CSegment3D& vectorA, const CSegment3D& vectorB); // cross product
friend CSegment3D operator%(CSegment3D vectorA, const CSegment3D& vectorB); // projection of vectorB onto vectorA
};