Variable Declaration

How do we declare var that would only be determined at run time? Say I would create a1, a2, a3...and so on but the number of var is not determined initially.
For example inside some block

int a1, a2, a3;

Or do you mean that the number of variables are unknown at compile time?
Last edited on
If you want a variable amount of variables determined at run-time you should use the std::vector container.
@vlad from moscow - unknown at runtime. would depend on the input of the user. I am actually making a code for chess.
In this case you can use either a dynamically allocated array or some container as for example std::vector.
@vlad from moscow, Thumper - thanks. I have read about the containers and I guess my problem was making the correct format to make the a container work. I have formulated a format to use vectors, I'll have it tested this weekend.

As I have mentioned, I am writing a chess engine code. I am now at the stage of storing sequences of generated positions for evaluation.
Good luck.:)
Now my question is: is it possible to create vectors or your own-defined classes?
Yes, you can make a vector of anything as long as the type meets a few requirements. Off the top of my head, I think it must be default constructable and copyable, but there may be others.
The only requirement of STL container value_types is that they must be copy constructable. (ยง23.1-5 C++ standard)
Thanks to all of you... it works.
Topic archived. No new replies allowed.