leileicats
September 25th, 2007, 11:02 PM
I am doing one project in the book "Data Structures and Algorithms with Object-Oriented Design Patterns in C++". The project is designing a 3D array class based on previous 2D array class.
Code as follows:
template<class T>
class Array2D
{
public:
Array2D(int w, int h):width(w), height(h), array(w*h) {}
... ...
protected:
int width, height;
Array<T> array;
}
template <class T>
class Array3D
{
public:
Array3D(int l, int w, int h):length(l), width(w), height(h), array(l) {}
... ...
protected:
int length, width, height;
Array< Array2D<T> > array;
}
I am planning to create a array with elements of 2D array. I could use the initializer "array(l)" to define the length of array. But the size of element "Array2D<T>" should be "width*height". But I don't know how to initialize the size of "Array2D<T>" in the class of Array3D.
Could anybody give me some advice please?
Code as follows:
template<class T>
class Array2D
{
public:
Array2D(int w, int h):width(w), height(h), array(w*h) {}
... ...
protected:
int width, height;
Array<T> array;
}
template <class T>
class Array3D
{
public:
Array3D(int l, int w, int h):length(l), width(w), height(h), array(l) {}
... ...
protected:
int length, width, height;
Array< Array2D<T> > array;
}
I am planning to create a array with elements of 2D array. I could use the initializer "array(l)" to define the length of array. But the size of element "Array2D<T>" should be "width*height". But I don't know how to initialize the size of "Array2D<T>" in the class of Array3D.
Could anybody give me some advice please?