Well basically operator overloading is defining your own operators for use with your class. Lets say you have 2 integers, and you use the minus sign to subtract them. That's intuitive. What does it mean to subtract some class from another one? It might not be as clear. So basically you define your own minus operator to perform whatever calculation you desire. The same theory applies to the ostream operator as well ( << ). I'll give you an example of this.
Here is the header file for a simple point class with overloaded operators as you mentioned.
Code:
#ifndef POINT_H
#define POINT_H
#include <iostream>
using namespace std;
class Point
{
private:
int m_x;
int m_y;
public:
Point( ) : m_x(0), m_y(0) { }
Point( int x, int y ) : m_x(x), m_y(y) { }
friend ostream& operator <<( ostream &os, const Point &pt )
{
os << "( " << pt.m_x << ", " << pt.m_y << " )";
return os;
}
Point operator -( const Point &pt )
{
return( Point( m_x - pt.m_x, m_y - pt.m_y ) );
}
};
#endif /* POINT_H */
EDIT:
Mathematically the difference between two points is a vector though. I simply return a Point for simplicity and to show a basic usage of operator overloading.