When is a const reference better than pass-by-value in C++11?

前端 未结 5 609
醉梦人生
醉梦人生 2020-12-04 17:13

I have some pre-C++11 code in which I use const references to pass large parameters like vector\'s a lot. An example is as follows:



        
5条回答
  •  無奈伤痛
    2020-12-04 18:09

    Remember that if you are not passing in an r-value, then passing by value would result in a full blown copy. So generally speaking, passing by value could lead to a performance hit.

提交回复
热议问题