An Array Example
Finally, here is an example showing how to use the array class to define and print a three-dimensional array of integers:
 
#include <rw/math/mtharray.h> // 1
#include <iostream.h>
int main()
{
RWMathArray<int> A; // 2
A.resize(3,3,3); // 3
A = 3; // 4
A(1,1,1) = 0; // 5
cout << A; // 6
}
//1 This statement declares the class RWMathArray<T> an array of type T.
//2 Here we define A to be an array of integers using the default constructor. This constructor takes no arguments and constructs a null (0- dimensional) array. Why use it? One reason is that such a constructor is required to declare C-style arrays of RWMathArray<T>s:
RWMathArray<double> aa[5];
Default constructors exist for all the vector, matrix, and array classes.
//3 The array is resized to be a three-dimensional array of size 3x3x3.
//4 Each element in the array is set to 3.
//5 In this line, the middle entry of the array A is set to 0.
//6 In the last line, the array is printed out.