Updating vector of class objects using push_back in various functions

元气小坏坏 提交于 2019-12-01 21:10:42

You should pass the vector by reference to modify the original global vector.

void addBook(vector<BookData>& books)
                            ^^^

Otherwise you are passing a copy of the original vector to the function and modifying that not the global version.

You need to pass your vector as a reference wherever necessary. In that specific instance, you just need to change

void addBook(vector<BookData> books)

to:

void addBook(vector<BookData>& books)

otherwise your function gets a copy of the vector, not a reference to the original one.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!