This is the version 61642155d60d2db275701e30 from 2021-10-11 11:34:45 comment: 'return'
c++ r-value references ed
- r-value ref parameters are l-values! (they have a name)
void g(const X &x);
void g(X && x);
void f(X && x) {
g(x); // will call g(const X &x)
}
- fix: std::move()
void f(X && x) {
g(std::move(x)); // will call g(X && x)
}
- don't return via std::move()
X f() {
X x;
return std::move(x); !!! NOPE, since x might already be at the location of the return target
}
Categories: c++, Programmieren