How to have a user create a new object/instance of a class
Hi, I apologise if this is a common question, or if I am going in the wrong direction entirely.
I have been trying to get a better understanding of classes. What I haven't been able to work out is how to let the user create a new instance (I think I am asking the right question).
For example: I have a class called Unit, and several classes that inherit from Unit - Car, Soldier, Robot etc. If I want to create a new car unit in my code, I would simply do
Is that correct so far?
If I wanted to make an RTS game, or even a simple phonebook application this wouldn't work (or would it?). I need to have a function (do you use the constructor?) along the lines of "create new unit of type X" or "create new car".
Is it simpler than I think? I hope so. Perhaps everytime you call the constructor it makes a seperate one, and I just have to initialise it with a unique ID number or similar?
I hope I have made sense. Any help/tips/links would be greatly appreciated, I have been at this for days now.