c++ - Passing a vector<class> myvector to an constructor and accessing it -
sorry if question similar posted already, don't know how word question properly. how can access "william" , "shakespeare" cout << passed author object shakespeare, passed vector of authors passed book object play?
class author{} //has private variables first_name , last_name , getter //functions in public. class book{ private: vector<author> author_mem; public: book(const vector<author>& author_fn):author_mem(author_fn){} vector<author> get_author_list() const {return author_mem;} } int main(){ const author shakespeare("william","shakespeare"); const vector<author> authors = {shakespeare}; const book play(authors); //initiial idea have //cout << play.get_author_list.at(0) }
i don't know how named accessors author
class, let's it's getfirstname
, getlastname
.
that should work:
cout << play.get_author_list().at(0).getfirstname(); cout << play.get_author_list().at(0).getlastname();
Comments
Post a Comment