I am having an issue with vectors and I can't seem to find the answer in the documentation on vectors. I made a class with functions inside and then added that class into a vector. However, I am not even sure if that is the right approach. From what I understand, when you put a class into a vector it allows for the class to be reused. Here is what I have in a nutshell.
1 2 3 4 5 6 7
1 2 3 4 5 6 7 8
vector< ClassName > classNameVector;
When I compile the program, there are no errors with the definition of the vector. The errors occur when I try and do anything with the vector. An example is taking input from the user and applying it to the name string inside of the class.
for( int i = 0; sizeOfVector > i; i++ )
vectorNumber = i + 1;
cout << vectorNumber << ". " << classNameVector[ sizeOfVector ].getValue();
1 2 3 4 5
classNameVector.resize( sizeOfVector + 1 );
cout << "Please enter a name in the form Last, First Middle:\n";
classNameVector[ sizeOfVector ].changeName( changedName );
So what I want to happen is the bottom code to run first The user is essentially creating a new entry (expanding the vector by 1) and enters a name. This passes the string to the function changeName (not shown but it is expecting a string atgument) which is in the class. That seems to go okay. Then the user has the option to display what was entered by using the top code which checks the size of the vector and prints a list in numbered form with the data. I ran a debug console to find out where it is crashing and I got the error