0% found this document useful (0 votes)
10 views

Design

This document describes a template Array class that can store multidimensional arrays of any type in C++. The class uses templates to support arrays of up to 2 dimensions of any type. It contains data members to store the array size, a pointer to the underlying data, and a flag. Constructors are provided to initialize arrays of different dimensions from a given value or by copying another array. A destructor is also defined to clean up memory.

Uploaded by

zhiwei6
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Design

This document describes a template Array class that can store multidimensional arrays of any type in C++. The class uses templates to support arrays of up to 2 dimensions of any type. It contains data members to store the array size, a pointer to the underlying data, and a flag. Constructors are provided to initialize arrays of different dimensions from a given value or by copying another array. A destructor is also defined to clean up memory.

Uploaded by

zhiwei6
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Array<Typename T,int D> e.g.

Array<double,2> A,B; //to store 2 dimensional array of doubles (matrix) Array<double,1> X,Y; //to store 1 dimensional array of doubles (vector) Class Members: int size[D]; // size[0] will be 1st dimension, size[1] will be 2nd dimension etc. T* data; // pointer to underlying data bool del; //flag for destructor

Constructor: Array<T,D>(); Array<T,D> E(); //Creates a D dimensional array with no elements //Constructor support for up to 2 dimensions first: Array<T,1> = X(int n); //Constructor for 1 dimension, n elements Array<T,2> = A(int m,int n); //Constructor for 2 dimensions, m*n elements Array<T,1> Y(T& k,int n); //1 Dimensional Array from k of size n Array<T,2> B(T& k, int m,int n); //2 Dimensional Array from k of size m*n Array<T,2> C= A; //Make a copy of A, there will be compile time error if A is not the same type Destructor: ~Array<T,D>();

You might also like