Why can't we implement both methods getAB() &&
and getAB()
, but can implement any one of these?
- Works: http://ideone.com/4EgObJ
Code:
struct Beta {
Beta_ab ab;
Beta_ab && getAB() && { cout << "1"; return move(ab); }
};
int main() {
Beta_ab ab = Beta().getAB();
return 0;
}
- Works: http://ideone.com/m9d0Tz
Code:
struct Beta {
Beta_ab ab;
Beta_ab && getAB() { cout << "2"; return move(ab); }
};
int main() {
Beta b;
Beta_ab ab = b.getAB();
return 0;
}
- Doen't works: http://ideone.com/QIQtZ5
Code:
struct Beta {
Beta_ab ab;
Beta_ab && getAB() && { cout << "1"; return move(ab); }
Beta_ab && getAB() { cout << "2"; return move(ab); }
};
int main() {
Beta b;
Beta_ab ab1 = b.getAB();
Beta_ab ab2 = Beta().getAB();
return 0;
}
Why are the first two examples of code works, but the last example does not work?