class Point
{
private:
double m_dX, m_dY, m_dZ;
public:
Point(double dX=0.0, double dY=0.0, double dZ=0.0)
{
m_dX = dX;
m_dY = dY;
m_dZ = dZ;
}
// Convert a Point into it's negative equivalent
friend Point operator- (const Point &cPoint);
// Return true if the point is set at the origin
friendbooloperator! (const Point &cPoint);
double GetX() { return m_dX; }
double GetY() { return m_dY; }
double GetZ() { return m_dZ; }
};
// Convert a Point into it's negative equivalent
Point operator- (const Point &cPoint)
{
return Point(-cPoint.m_dX, -cPoint.m_dY, -cPoint.m_dZ);
}
// Return true if the point is set at the origin
booloperator! (const Point &cPoint)
{
return (cPoint.m_dX == 0.0 &&
cPoint.m_dY == 0.0 &&
cPoint.m_dZ == 0.0);
}
I don't understand:
With overloading the "-" operator, he uses:
Point operator- (const Point &cPoint)
But with overloading the "!" op’, he uses:
booloperator! (const Point &cPoint)
But why isn’t it?:
Point operator! (const Point &cPoint)
What is fundamentaly different about the "-" & "!" unary operators that means the "-" overload puts the class as the function type, but with the "!" overload, it puts "bool" as the function type?
You say "function type", but that is not the correct word. What you mean to say is "return type", and it may help to get a refresher on functions to understand what return types are: http://www.cplusplus.com/doc/tutorial/functions/
To answer your question directly, the unary ! operator (unary logical not) is traditionally used to obtain a value of type bool