Should copy assignment operator pass by const reference or by value?

后端 未结 1 1669
孤街浪徒
孤街浪徒 2021-02-09 03:16

Prior to C++11, it has always been the case that copy assignment operator should always pass by const reference, like so:

template 
ArrayStack&         


        
1条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-09 04:04

    Prior to C++11, it has always been the case that copy assignment operator should always pass by const reference

    That is not true. The best approach has always been to use the copy-and-swap idiom, and that's what you're seeing here (although the implementation in the body is sub-optimal).

    If anything, this is less useful in C++11 now that you have a move assignment operator too.

    0 讨论(0)
提交回复
热议问题