lundi 5 janvier 2015

Why can't RHR functions be overloaded?

I could see something like the following being useful:



class A {
public:
const vector<int>& vals() const {
return val;
}

vector<int> vals() && {
return std::move(val);
}
private:
vector<int> val;
}


But I get a compiler error with g++:



error: ‘vector<int> A::foo() &&’ cannot be overloaded


I would think you'd be able to do the same sort of overloading that you can with const functions. This would be less useful for the above accessor, and more useful for operators.


Aucun commentaire:

Enregistrer un commentaire