I'm trying to figure out how to use a getter function with a particular object that is contained within a vector that is in a separate class. Ok, there's a class Patron that contains GetNumBooks(), and there's a class PatronList that contains vector patrons, how would I within class Loan call GetNumBooks(for a patron object within vector patrons) in a conditional?
Loan class: https://pastebin.com/1KSKFvmS Patron class: https://pastebin.com/F7amyfHb PatronList class: https://pastebin.com/8ARsHQQy
I've tried the following:
in PatronList:
vector<Patron>* ReturnVec(){
vector<Patron>* PatPtr = new vector<Patron>;
PatPtr = &patrons;
return PatPtr;
}
in Loan:
void Loan::Test(Patron myPatron){
vector<Patron>* here = new vector<Patron>;
here = list.ReturnVec();
here->push_back(myPatron);
here->at(0).SetNumBooks(11);
cout << here->at(0).GetNumBooks();
}
Which seems to work but...I suppose I want to know if there's a better solution. Are pointers even necessary? If so, do I really need to declare a pointer in both Test and ReturnVec?