Every one of the Property objects you create on line 2 (with constructor parameters going from line 3 to line 8) ceases to exist when the loop goes around again.
You create one (named propertyCard), and then it is destructed, and then you create one (named propertyCard), and it is destructed, and you create one (named propertyCard), and it is destructed, and so on. After line 9, they have all been destructed.
If you want to have more than one at any one time, you'll need to either give them different names, or don't bother with names and just put them into a vector.
1 2 3 4 5 6 7 8 9 10 11 12 13
vector<Property> vectorOfProperties;
for (size_t i = 0; i + 5 < myPropertyClassCreator.size(); i += 6) {
Property propertyCard(
stringToInt(myPropertyClassCreator[i + 0]),
myPropertyClassCreator[i + 1],
myPropertyClassCreator[i + 2],
stringToInt(myPropertyClassCreator[i + 3]),
stringToInt(myPropertyClassCreator[i + 4]),
stringToInt(myPropertyClassCreator[i + 5]));
vectorOfProperties.push_back(propertyCard);
}
// now vectorOfProperties contains all the Property objects that were made.
@Moschops thank you for the reply, It says I need to create a pointer as the getName function requires it. I thought doing it the vector way would mean I wouldn't have to have a pointer and do polymorphism.
1 2 3
for (int j = 0; j < vectorOfProperties.size(); j++){
cout << vectorOfProperties[j].getName << endl; //says I need pointer
}