C++ - passing references to std::shared_ptr or boost::shared_ptr

前端 未结 17 1741
日久生厌
日久生厌 2020-11-28 01:20

If I have a function that needs to work with a shared_ptr, wouldn\'t it be more efficient to pass it a reference to it (so to avoid copying the shared_ptr

17条回答
  •  佛祖请我去吃肉
    2020-11-28 01:59

    In addition to what litb said, I'd like to point out that it's probably to pass by const reference in the second example, that way you are sure you don't accidentally modify it.

提交回复
热议问题