I have a class with fields like firstname, age, school etc. I need to be able to store other information like for instance, where they have travelled, and what year it was in. I cannot declare another class specifically to hold travelDestination and what year, so I think a struct might be best. This is just an example:
struct travel {
string travelDest;
string year;
};
The issue is people are likely to have travelled different amounts. I was thinking of just having an array of travel structs to hold the data. But how do I create a fixed sized array to hold them, without knowing how big I need it to be?
Perhaps I am going about this the completely wrong way, so any suggestions as to a better way would be appreciated.
I realise there is essentially no difference between a class and struct, but for the purposes of assignment criteria I am not allowed a "class", so yeah.
structdefines a class. So does the keywordclass). Don't be afraid of defining as many classes as you need in C++, there isn't a tax on them ;-)struct travel { string dest; int year; void print() {std::cout << year <<": "<< dest << "\n"; };an "unapproved extra class", or not? Probably yes, but why does it matter to the assignment whether you do it or not? And so on.