Updating vector of class objects using push_back in various functions

后端 未结 2 954
余生分开走
余生分开走 2021-01-20 03:50

I have a vector of class objects I\'ve created in main by reading in a data file. I\'m then passing around the vector to several different files containing functions that p

2条回答
  •  长发绾君心
    2021-01-20 04:09

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

    void addBook(vector& books)
                                ^^^
    

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

提交回复
热议问题