Simple pointers (dynamic memory allocation)

Im having difficulty with a program that needs to create a certain number of objects depending on the value of variable.
Im working in c++

I want to do this

digit is a class
item is an int with value 6

here is a snippet:

1
2
digit *token;
token = new digit[item];



this is bad code how can I create 6 digit objects given that the value of item is 6? Or is this impossible?
The snippet looks fine to me. Just remember to delete[] when you are done. Perhaps you need to be more specific?
the problem is that the constructor is overloaded and takes either int or string
so it gives me this error:

no appropriate default constructor available
You can't use new [] if you aren't able to use the default constructor.
Blargh, screw new [], use malloc, a loop, and a init function if you need pointers to dynamic arrays of classes that need initializers.
Or, just use the std::vector template which will save you from a lot of other trouble.
Topic archived. No new replies allowed.