Vector Association

I am curious as to how I can assign a pre-determined vector (of size 3) to another variable.

This is just a very small piece of the code (I do not want to attach the whole program):

1
2
3
double[] sthree;
double Alkaid[3] = {-61.8,159.2,-122.2};
sthree = Alkaid;


I have tried all sorts of ways to classify 'sthree' but cannot seem to get the right format.

My GCC errors when trying to form the executable are (for the entire program):

"expected unqualified-id before '[' token" (referring to sthree)
and
"'sthree' was not declared in this scope"

Any input would be appreciated.

Thanks,
Justin
This depends on what you want to do with it.

The easiest way is to do this:

1
2
3
double* sthree;
double Alkaid[3] = {-61.8,159.2,-122.2};
sthree = Alkaid;


But if you ever want to change Alkaid without changing sthree, you'll need another method.

Here's something else:
1
2
3
4
5
6
#define VECTOR_SIZE 3

double sthree[VECTOR_SIZE];
double Alkaid[VECTOR_SIZE]  = {-61.8,159.2,-122.2};

memcpy(sthree, Alkaid, VECTOR_SIZE * sizeof(double));


http://www.cplusplus.com/reference/clibrary/cstring/memcpy/
Last edited on
The first one will do just fine, and it worked!
And I'm sure that that I'll be coming across the second sooner or later.

THANKS,
Justin
Topic archived. No new replies allowed.