使用引用限定符的例子

13.57 编写Foo类。

Foo.h

#ifndef FOO_H
#define FOO_H
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

class Foo
{
public:
    Foo sorted() &&;
    Foo sorted() const &;
private:
    vector<int> data;
};
#endif // FOO_H

Foo.cpp

#include"Foo.h"

Foo Foo::sorted() &&
{
    sort(data.begin(),data.end());
    return *this;
}

Foo Foo::sorted() const &
{
    cout<<"sorted&"<<endl;
    //sort(ret.data.begin(),ret.data.end());
    return Foo(*this).sorted();
}
原文地址:https://www.cnblogs.com/wuchanming/p/3933766.html