引用限定符 reference qualifiers

新功能:引用限定符 reference qualifiers
这样子玩:

class A {
public:void doWork() &; // this version of doWork applies
// only when *this is an lvalue
void doWork() &&; // this version of doWork applies
}; // only when *this is an rvalue
…
A makeA(); // factory function (returns rvalue)
A w; // normal object (an lvalue)
…
w.doWork(); // calls A::doWork for lvalues   调用左值函数版本
// (i.e., A::doWork &)
makeA().doWork(); // calls A::doWork for rvalues  调用右值版本函数
// (i.e., A::doWork &&)

猜你喜欢

转载自blog.csdn.net/shujianlove0/article/details/84564578