Jul 28, 2013 at 3:37pm UTC
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.
Jul 28, 2013 at 3:39pm UTC
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
Jul 28, 2013 at 3:40pm UTC
Jul 28, 2013 at 9:24pm UTC
@vlad from moscow - unknown at runtime. would depend on the input of the user. I am actually making a code for chess.
Jul 28, 2013 at 9:25pm UTC
In this case you can use either a dynamically allocated array or some container as for example std::vector.
Jul 29, 2013 at 11:29am UTC
@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.
Jul 29, 2013 at 11:56pm UTC
Now my question is: is it possible to create vectors or your own-defined classes?
Jul 30, 2013 at 12:08am UTC
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.
Jul 30, 2013 at 12:55am UTC
The only requirement of STL container value_types is that they must be copy constructable. (§23.1-5 C++ standard)
Jul 30, 2013 at 9:02pm UTC
Thanks to all of you... it works.