I have created a very simple class Movie which allows several attributes of a movie to be stored and accessed, ex Title, Director, Rating, etc.
I would like to implement some code that allows new Movie objects to be created dynamically depending on how many movies the user would like to input.
I have overloaded the '+' operator to allow an int to be concatenated with a string ("string" + 1 = "string1"), and I basically want to iterate the int in a loop until the user is done inputting movies. Each new movie object should be referenced with using the string+int that is updated each iteration. For example, the first movie will be created as follows: Movie mov1(); second movie Movie mov2() etc.
My problem is how to get C++ to evaluate the string such that I can use its value as the name of a new object. If I implement the following code:
1 2 3 4 5 6
|
int n = 1;
do {
string s = "mov" + n;
Movie s();
n++;
} while (!QUIT);
|
the compiler will try to create every Movie object with the reference s. This of course will not work for me. I've been told that I can use the <map> or <vector> libraries to do this, but I know very little about using these.
Any suggestions are greatly appreciated here.