I have a class Node and want to declare an initially unknown number of instances of this class at run-time. First the program determines the number of nodes (num_n) from the user and then I want to define num_n objects.
I have crudely got around this by defining a maximum number of nodes and storing them in a vector so they can be accessed sequentially and edited according the the user input. But, I am wondering is it possible to use a string (e.g. n1, n2, n3...), or something else, to declare these more efficiently:
include "Node.h"
int main()
{
int num_n;
cout << "Enter number of nodes:\n";
cin >> num_n;
for (int i=0; i<num_n; i++)
{
// Can I declare num_n objects with names n1, n2, n3 etc?
Node n(i) = Node();
// Set values of members of Node here
}
}
I hope this makes sense as I'm not really sure what I am asking. I've tried searching the forum and google but haven't been able to find anything related to what I'm trying to do.
Thanks in advance for your help :)