What's a use case for overloading member functions on reference qualifiers?

前端 未结 4 878
天涯浪人
天涯浪人 2020-11-28 08:22

C++11 makes it possible to overload member functions based on reference qualifiers:

class Foo {
public:
  void f() &;   // for when *this is an lvalue
           


        
4条回答
  •  旧时难觅i
    2020-11-28 08:42

    If f() needs a Foo temp that is a copy of this and modified, you can modify the temp this instead while you can't otherwise

提交回复
热议问题