I have two arrays of pointers to doubles that I need to swap. Rather than just copy the data within the arrays, it would be more efficient just to swap the pointers to the arrays. I was always under the impression that array names were essentially just pointers, but the following code receives a compiler error:
double left[] = {1,2,3};
double right[] = {9,8,7};
double * swap = left;
left = right; // Error "ISO C++ forbids assignment of arrays"
right = swap; // Error "incompatible types in assignment of `double*' to `double[((unsigned int)((int)numParameters))]'"
Creating the arrays dynamically would solve the problem, but can't be done in my application. How do I make this work?
&to get the addresss of a pointer). During pointer assignments one pointer's value is taken and assigned to another pointer. You can't do that on arrays because, by the language concept, they denote adresses itself. According to this, you are trying to do something like0x23ff10 = 0x23ff44assuming that left is0x23ff10and right is0x23ff44.