Returning Vectors standard in C++

后端 未结 4 1476
被撕碎了的回忆
被撕碎了的回忆 2021-01-26 12:20

Now, I know this is a common question, but I haven\'t been able to really find a straight answer on this. This is really a question about standards. I am working on a project in

4条回答
  •  轮回少年
    2021-01-26 12:52

    If you can, always use a reference (&) instead of using the class itself. This even refers to smart pointers (std::shared_ptr), because you will avoid an extra copy even of the pointer itself. And just to make sure that your returned pointer does not get overwritten, pre-pend const to it, so:

    void Function(const std::shared_ptr &someObject);
    

提交回复
热议问题