Updating vector of class objects using push_back in various functions

后端 未结 2 952
余生分开走
余生分开走 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:21

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

    void addBook(vector books)
    

    to:

    void addBook(vector& books)
    

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

提交回复
热议问题