Move-only objects can be passed into functions as r-value reference parameters and as regular no-reference parameters. What is the difference between these two cases?
See noRValueReference and rValueReference in the following example:
struct MoveOnly {
MoveOnly() = default;
MoveOnly(MoveOnly&&) = default;
MoveOnly& operator=(MoveOnly&&) = default;
MoveOnly(const MoveOnly&) = delete;
MoveOnly& operator=(const MoveOnly&) = delete;
};
void noRValueReference(MoveOnly val) {}
void rValueReference(MoveOnly&& val) {}
int main() {
MoveOnly a, b;
noRValueReference(std::move(a));
rValueReference(std::move(b));
}
Aucun commentaire:
Enregistrer un commentaire