194 Introduction to C++ Programming and Graphics
//--- CLASS DEFINITION
template <class T>
class point
{
public:
point(); // default constructor
point(T valuex, T valuey);
T getx() const;
T gety() const;
void print() const;
void move(T dx, T dy);
point<T> operator + (point<T>); // overload +
private:
Tx;
Ty;
};
Note that the class definition includes the overloading of the + operator. Re-
placingTwith a regular data type such asdoubleyields familiar code.
The class implementation is:
template <class T>
point<T>::point(T valuex, T valuey)
{
x = valuex;
y = valuey;
}
template <class T>
T point<T>::getx() const
{
return x;
}
template <class T>
T point<T>::gety() const
{
return y;
}
template <class T>
void point<T>::print() const
{
cout << x <<""<<y<<endl;
}
template <class T>