I am working with dynamic arrays which have been created using <vector>. For convenience, I have created a typedef :
typedef vector<double> C1DArray;
In the main program, several variables are created using this definition which, at the moment, means working with arrays of size 30.
main()
{
. . .
// Declare several dynamic arrays that will be re-sized appropriately later.
C1DArray WORK1_Array, WORK2_Array, WORK3_Array, WORK4_Array;
. . .
return 0;
}
Several sub-routines only need to work with a particular range of these arrays. For example, SUB-ROUTINE1 takes in WORK2_Array and only touches, say, elements 5 through 25: WORK2_Array[4] - WORK2_Array[24]. In other words, it doesn't need to access all 30 elements of the array. I would like to pass the address of WORK2_Array[4] into the sub-routine so that, within the sub-routine, a simple for-loop could be used that starts the indexing at 0. However, I can't get it working. Following is one of the attempts I have made so far.
Define SUB-ROUTINE1 such that it takes in a pointer to the address of a specific element within a dynamic array (WA1):
void SUBROUTINE1 (int N, int L1, C1DArray CC, C1DArray& CH, C1DArray* WA1, C1DArray* WA2){
double variable1;
for (int i = 0, i < 20; i++) variable1 = WA1[i] + WA2[i];
CH[15] = variable1;
return;
}
In the main program, I try to call SUB-ROUTINE1 as follows:
SUBROUTINE1(30, 5, Array1, Array2, &WORK2_Array[4], &WORK2_Array[17]);
However, the compiler does not like this code. I have tried other ways of doing it but am presently stumped. The error message says, "Cannot convert argument from "double" to "C1DArray."
How can I pass the address of a specific element of a dynamic array to a sub-routine so that, within the sub-routine, it can be treated as a regular array (though of reduced range)?
Your help is appreciated.