is there any specific case where pass-by-value is preferred over pass-by-const-reference in C++?

后端 未结 15 1889
臣服心动
臣服心动 2020-12-06 08:03

I read that they are conceptually equal. In practice, is there any occasion that

foo(T t) 

is preferred over

foo(const T&         


        
15条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-06 08:23

    Don't forget that there are cases where there is a difference - when you're dealing with objects that have strange copy/assignment semantics.

    auto_ptr<> is the classic example - pass those around by value without thinking about the consequences and you may end up with a mess.

提交回复
热议问题