Class Name Creating Problem.

Hello everyone, I need to know how to make an instance of a class with a different name each time the user wants to make a new instance of that class. For example say I have the class car and I make an instance of that car. (car ford;) How would I be able to loop back to the making of the instance and create a new name for the instance each time, such that car ford; car ford1; car ford2; car fordn; ect.

Any idea's or thoughts about how I can go about doing this? Thanks.

-Arthur
As a general rule, if you find yourself naming things "x1, x2, x3", you're doing it wrong.

What you can do instead is make a vector of cars:

 
vector<car> fords;


Then when the user wants to create a new one:

 
fords.push_back( car() );  // create a new car 


You can then access individual cars with an index:

1
2
3
4
5
6
int whicheverfordyouwant = 3;  // we want the 4th car

fords[ whicheverfordyouwant ].DoSomething();

// or
fords[3].DoSomething();
Thank you Disch, I will look into Vectors and there applications.
After doing some research I think this is a good way for it to be done, but I'm having trouble getting it to actaully work. Any suggestions?
Topic archived. No new replies allowed.