Passing vectors by reference

前端 未结 3 643
野性不改
野性不改 2021-02-01 05:24

If I have a vector of objects in one class which I want to change in another, I would try and pass all the information by reference.

What exactly do I need to pass by re

3条回答
  •  执笔经年
    2021-02-01 05:48

    Another option is to pass around iterators instead of containers. This is the approach the standard library takes in . They are slightly more verbose at the calling site, but they have the advantage that they work for parts of a collection as well as complete collections and decouples the algorithm from the container.

    Lastly, of course, it's worth while checking you know your algorithms as there may already be one that does what you want.

提交回复
热议问题