Neil Zanella wrote:
> Here is my way of making use of std:
air<class T1, class T2>:
>
> #include <iostream>
> #include <utility>
>
> template<class T1, class T2>
> class Coordinate: public std:
air<T1, T2> {
> public:
> Coordinate(T1 x, T2 y): std:
air<T1, T2>(x, y), x(first),
> y(second) { } T1 &x;
> T2 &y;
> };
The above class cannot be assigned, or copy constructed. Plus: do not use
inheritance when composition suffices:
template<class T1, class T2>
struct Coordinate {
Coordinate():
store(T1(),T2()), x(store.first), y(store.second) { }
Coordinate(T1 px, T2 py):
store(px,py), x(store.first), y(store.second) { }
Coordinate(Coordinate const &o):
store(o.store), x(store.first), y(store.second) { }
Coordinate operator=(Coordinate const &o)
{ store = o.store; }
T1 &x;
T2 &y;
private:
std:

air<T1, T2> store;
};
Also note that the above class will be bigger than the pair. In case of
int, on a usual architecture it will be twice as big. So IMHO you are
better off having accessor functions - if you must access the elements from
the outside.
template<class T1, class T2>
struct Coordinate {
Coordinate(): store(T1(),T2()) { }
Coordinate(T1 px, T2 py): store(px,py) { }
Coordinate(Coordinate const &o): store(o.store) { }
Coordinate operator=(Coordinate const &o) { store = o.store; }
T1 &x() {return store.first; }
T2 &y() {return store.second; }
private:
std:

air<T1, T2> store;
};
But to be honest I would just leave std:

air out of this completely and
make a little template struct of my own, with the right names.
--
WW aka Attila