重载运算符,可以定义运算符为自己想要的效果,简化程序,以重载<运算符为例:
#ifndef BOX_H
#define BOX_H
class Box{
public:
	Box(double aLength=1.0,double aWidth=1.0,double aHeight=1.0);
	double volume() const;
	double getLength() const;
	double getWidth() const;
	double getHeight() const;
	
	//重载运算符<
	bool operator < (const Box& aBox) const
	{
		return volume()<aBox.volume();
	}
private :
	double length;
	double width;
	double height;
};
#endif
这样就可以直接调用<运算符直接比较体积。
原文:http://blog.csdn.net/u010142437/article/details/38402287