M
Mark
i need to make a class that can store anything (integers,objects,etc)
it needs to maintain a list of pointers to these objects
the list needs to be resized to accomodate more elements
i can't use any special classes
i just can't seem to figure it out.
i've got a pointer,
void *storage
which will point to the start of the list
then there will be one pointer, every 4 bytes (sizeof(void*))
which i *think* i can access by doing
storage[index*sizeof(void*)]
i'm not sure if I need to cast that to a void pointer or not, since
that's already what it's defined as...
but then to resize this beast, i'm completely lost
i create a new void pointer..
void* temp = new void*[length]
where length is the new size (how many pointers it will hold)
which should allocate length*4 bytes of memory...
and then i tried doing
for(int i=0; i<count; i++)
{
temp = storage[i*size];
}
to copy the pointers over
where count is the number of elements currently in the stash, but my
compiler complains...
`void*' is not a pointer-to-object type
pointer of type `void *' used in arithmetic
and...i don't really know what else to do.
any help?
it needs to maintain a list of pointers to these objects
the list needs to be resized to accomodate more elements
i can't use any special classes
i just can't seem to figure it out.
i've got a pointer,
void *storage
which will point to the start of the list
then there will be one pointer, every 4 bytes (sizeof(void*))
which i *think* i can access by doing
storage[index*sizeof(void*)]
i'm not sure if I need to cast that to a void pointer or not, since
that's already what it's defined as...
but then to resize this beast, i'm completely lost
i create a new void pointer..
void* temp = new void*[length]
where length is the new size (how many pointers it will hold)
which should allocate length*4 bytes of memory...
and then i tried doing
for(int i=0; i<count; i++)
{
temp = storage[i*size];
}
to copy the pointers over
where count is the number of elements currently in the stash, but my
compiler complains...
`void*' is not a pointer-to-object type
pointer of type `void *' used in arithmetic
and...i don't really know what else to do.
any help?