Is there an elegant way to swap references in C++?

前端 未结 4 1488
心在旅途
心在旅途 2021-01-11 10:51

Sometimes classes are referencing other classes. Implementing std::swap() for such classes cannot be straightforward, because it would lead to swapping of origi

4条回答
  •  逝去的感伤
    2021-01-11 11:27

    Essentially what you would like to do, if I understand your example, is to rebind references. This you cannot do in C++. You can either swap the values in the referred to objects, or you can use pointers.

提交回复
热议问题