[prog] Definining an array in Visual C++
Elizabeth Barham
lizzy at soggytrousers.net
Tue Mar 25 21:06:23 EST 2003
Here's a slight modification of your code, Kathryn, so as to handle
double []'s:
template <class _Tp>
class D_ArrayHelper{
_Tp *tp;
public:
D_ArrayHelper(_Tp * p): tp(p) {}
_Tp & operator[](int x) { return tp[x] ; }
};
template <class _Tp>
class DArray {
_Tp *tp;
size_t n;
public:
DArray(size_t n_size): n(n_size) {
tp = new _Tp[n*n];
}
~DArray() { delete [] tp; }
_Tp &operator () (size_t i, size_t j) {
// assert(i < n && j < n);
return tp[i*n+j];
}
D_ArrayHelper<_Tp> operator[](int x) { return D_ArrayHelper<_Tp>(tp + n * x); }
};
Elizabeth
More information about the Programming
mailing list