(E-Mail Removed) wrote:

If you are not learn design of classes, but learn C++ class's

implementation, then

replace:

> T getX();

> T getY();
to

T getX()const;

T getY()const;

and

> void setX(T x);

> void setY(T y);
to

void setX(const T& x);

void setY(const T& y);

and

> template <class T>

> Tuple<T>::Tuple(void)

> {

> _values = new T[2];

> _values[0] = 0;

> _values[1] = 0;

> }
to

/*Tuple<T>::*/ enum { item_x=0, item_y, total_items };

template <class T>

Tuple<T>::Tuple():_values(0)

{

//new must not return NULL

_values = new T[total_items];

_values[item_x] = 0;

_values[item_y] = 0;

}

and

> template <class T>

> Tuple<T>::Tuple(T x, T y)

> {

> _values = new T[2];

> _values[0] = x;

> _values[1] = y;

> }
to

template <class T>

Tuple<T>::Tuple(const T& x, const T& y):_values(0)

{

//new must not return NULL

_values = new T[total_items];

_values[item_x] = x;

_values[item_y] = y;

}

and

> template <class T>

> Tuple<T>::~Tuple(void)

> {

> }
to

template <class T>

Tuple<T>::~Tuple(){ delete _values; _values=0; }

and

> template <class T>

> T Tuple<T>::get?() { return _values[?]; }
to

template <class T>

T Tuple<T>::get?()const { return _values[item_?]; }

and

> template <class T>

> void Tuple<T>::set?(T ?) { _values[?] = ?; }
to

template <class T>

void Tuple<T>::set?(const T& ?) { _values[item_?] = ?; }

And create at least

template <class T>

class Tuple

{

....

private:

Tuple(const Tuple& ):_values(0){abort();}

void Tuple<T>:

perator = (const Tuple& ){abort();}

};

And if you are using exceptions, define throw(type) for all class's

members.

> But when I use double or

> float, the array points to garbage and any updates to array elements

> make no difference.
Do printing of data for set/get members.