classWidget { public: voiddoWork() &; // this version of doWork applies // only when *this is an lvalue voiddoWork() &&; // this version of doWork applies }; // only when *this is an rvalue
Widget makeWidget(); // factory function (returns rvalue) Widget w; // normal object (an lvalue)
w.doWork(); // calls Widget::doWork for lvalues // (i.e., Widget::doWork &) makeWidget().doWork(); // calls Widget::doWork for rvalues // (i.e., Widget::doWork &&)