Random Objects

Can anyone point me in the right direction, like a tutorial site, on how to create a random amount of objects?

Thanks
create a dynamic array (randomly) of object pointers

then loop the data in via a for statement based on the randomly generated number of times and fill them in...

look for array of objects
look into the random class (if you haven't already)
dynamically creating objects

and if you are new to c++ look into loops but from the sounds of things you are not.
1
2
3
4
5
6
MyClass **myArray; //pointer to an array of MyClassPointers
myArray = new MyClass [some random number];

for(i = 0; i < some random number; i++){
    myArray[i] = new MyClass;
}



Last edited on
That helps! Thank you! :)
Arrays are complicated and rarely useful. Use vectors, like you're supposed to in C++ (or other containers that aren't arrays)

vector<MyClass> myVector(some random number);
Topic archived. No new replies allowed.