template<class T>
class Array
{
public:
Array(int size) { p_ = new T[size]; size_ = size; };
~Array() { delete []p_; };
T& operator[](const int i) const;
private:
T *p_; // the pointer
int size_; // the size of the pointer
};
template<class T>
inline T& Array<T>::operator [](const int i) const
{
if (i >= size_)
cout << "Out of bounds " << i << endl;
return(*(p_+i));
}
|
Array < float > float_array(5); // create 5 floats
float_array[0] = 1.0f;
This works well as expected but how would I extend it to be able to handle multiple dimensional arrays?
float_array[0][3] = 3; // how to do something like that??
Note: There more operators that should be defined which are not shown)
Edited by - Void on 9/18/00 4:45:52 AM