The example below shows basic usage of arrays:
// Creating and initialising a 1-D array of integers TArray<int> ia(5); EnumeratedSequence es; es = 24, 35, 46, 57, 68; ia = es; cout << "Array<int> ia = " << ia; // 2-D array of floats TArray<r_4> b(6,4), c(6,4); // Initializing b with a constant b = 2.71828; // Filling c with random numbers c = RandomSequence(); // Arithmetic operations TArray<r_4> d = b+0.3f*c; cout << "Array<float> d = " << d;
The copy constructor shares the array data, while the assignment operator copies the array elements, as illustrated in the following example:
TArray<int> a1(4,3); a1 = RegularSequence(0,2); // Array a2 and a1 shares their data TArray<int> a2(a1); // a3 and a1 have the same size and identical elements TArray<int> a3; a3 = a1; // Changing one of the a2 elements a2(1,1,0) = 555; // a1(1,1) is also changed to 555, but not a3(1,1) cout << "Array<int> a1 = " << a1; cout << "Array<int> a3 = " << a3;