Ref qualifiers are a C++11 feature that allow member functions to be specialized based on whether the object is an lvalue or rvalue. The post explains the three forms: const& (lvalue with const), & (lvalue only), and && (rvalue only), and how they can be combined with =delete to produce compile errors. A practical use case is demonstrated with a fluent/builder-style Logger class, where setter methods are && ref-qualified so they can only be chained on temporaries, preventing misuse on named variables. Additional use cases include resource management (move vs copy depending on value category) and safe handling of temporaries in range-for loops.
Sort: