Reputation: 27629
I am trying to add the following:
I have an array of double pointers call A. I have another array of double pointers call it B, and I have an unsigned int call it C.
So I want to do:
A[i] = B[i] - C;
how do I do it? I did:
A[i] = &B[i] - C;
I don't think I am doing this correctly.
Edit: What I want to do is, take the value at index i of the double pointer array and subtract an int from it, then store that result into a double pointer array at index i.
Upvotes: 0
Views: 310
Reputation: 21226
What you want is:
&( *B[i] - C )
But i think you cannot assign it directly to A[i]. First you have to create a temporary (T) array of double.
for(int i=0; i< size_of_B; i++){
T[i] = *B[i] - C;
}
for(int i=0; i< size_of_T; i++){
A[i] = &T[i];
}
Upvotes: 0
Reputation: 523224
C++ doesn't have a simple syntax for mapping, you either
(1) Use a loop
for (int i = 0; i < 1482; ++ i)
A[i] = B[i] - C;
(2) Use std::transform
in <algorithm>
:
#include <functional>
#include <algorithm>
...
std::transform(B, B+1482, A, std::bind2nd(std::minus<double>(), C));
(There may be a Boost library to simplify this.)
Upvotes: 0
Reputation: 1916
Your question is a bit unclear, but if A and B are arrays of pointers to double and you want to change each pointer with a fixed amount of exactly C, then, for each element in A:
A[i] = B[i] - C;
should do it. &B[i] takes the address of the pointer itself, so it is a completely different thing.
sample code:
for(int i = 0; i < size_of_A; ++i) A[i] = B[i] - C;
Upvotes: 4