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

后端 未结 15 1926
臣服心动
臣服心动 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:22

    Some routines require a copy, and so should not be pass by reference. For example, a chess playing program's move generator might need a copy of the current position to work on (recursively) rather than actually modifying the original instance of the position.

提交回复
热议问题