class storage space? need help.

hello all.

I want to know a couple of things. I want to make an array to save space for a class that I'm making. then I want to instantiate a temp pointer of that information then push it into the array. Following that I want to rewrite that pointer. I got this concept from when I programmed in AS3. I don't know if this is efficient so if there's a better way then I'm listening. Here's some pseudo-code of what I'm looking for.

1
2
3
4
5
6
7
8
9
10
11

//create holder array
array sample[x];
//x equals max number of active samples

//temp sample
object sample = new sample();

//a loop that finds the first null in sample[] and passes it to int i
sample[i] = sample;


I'll need to be able to write over object sample (not the array) over and over without using extra space. I guess I could just write straight to the array, but I'm not sure how to instantiate the information directly to the array either.

if any one understands what I'm asking and can help, thank you VERY VERY much. Thanks for taking the time to look at this either way.
What you are looking for is a array of pointers to sample not a array of samples.
http://stackoverflow.com/questions/859634/c-pointer-to-array-array-of-pointers-disambiguation

 
array sample[x];


would be:
 
array *sample[x];


The other option is operator overload '=' for samples to do the what you want with sample[i] = sample; What you have in your code is a type mismatch between your array and the pointer to the object. The Array is not expecting dynamically allocated objects because of the way it is defined.
ok, so using my actual code, would it look something like this?

1
2
3
4
5
6
TestCode *enemies[100];


testCode  *enemy = new enemy(arg);
enemies[i] = enemy;


well I think I got the answer to all my questions. Thanks so much for you help and guidance.

if I'm even close that would be great.
i'm trying to learn something since my teacher for my class isn't really teaching much, and can't seem to answer questions. Thanks a ton for all help.
Last edited on
Topic archived. No new replies allowed.