W
whiskers
Hello, gurus. I spent an hour looking for the answer to this and
couldn't find one that pleased me (I don't want to use a base class,
which seems to be a solution).
So I have a function that takes (void * array) as a parameter. This
function will be called automatically a couple hundred times, I can't
change the declaration.
I need to pass the following data to the function:
vector<CustomStruct1> list // over 1500 entries
CustomStruct2 sixstructmembers
double p1
double p2
What I want to be able to do, is pass these 4 data structures in via
(void * array) without having to make them global (that's my last
resort)
void * array[4];
array[0] = &list;
array[1] = &sixstructmembers;
array[2] = &p1;
array[3] = &p2;
So now "array" should contain 4 pointers, each to a different data
structure.
My problem is dereferencing the pointers. When I get into the function,
I want to do something like
double * p2 = (double*)array[3] but that doesn't work, I'm guessing
because the compiler doesn't know what [3] means in this sense (no size
for void*). How do I work around this?
After thinking too much about it, I'm getting lost in all the
indirection. Is it a valid idea to use int * array[4];
array[0]=(int)&list; and then cast the array in the function as int *
newarray = (int*)array? Somehow that seems a little hackish.
couldn't find one that pleased me (I don't want to use a base class,
which seems to be a solution).
So I have a function that takes (void * array) as a parameter. This
function will be called automatically a couple hundred times, I can't
change the declaration.
I need to pass the following data to the function:
vector<CustomStruct1> list // over 1500 entries
CustomStruct2 sixstructmembers
double p1
double p2
What I want to be able to do, is pass these 4 data structures in via
(void * array) without having to make them global (that's my last
resort)
void * array[4];
array[0] = &list;
array[1] = &sixstructmembers;
array[2] = &p1;
array[3] = &p2;
So now "array" should contain 4 pointers, each to a different data
structure.
My problem is dereferencing the pointers. When I get into the function,
I want to do something like
double * p2 = (double*)array[3] but that doesn't work, I'm guessing
because the compiler doesn't know what [3] means in this sense (no size
for void*). How do I work around this?
After thinking too much about it, I'm getting lost in all the
indirection. Is it a valid idea to use int * array[4];
array[0]=(int)&list; and then cast the array in the function as int *
newarray = (int*)array? Somehow that seems a little hackish.