Vote count:
0
I'm having trouble understanding why the following (at least according to gcc 4.8) is legal in C++11:
// This class manages a non-copyable resource.
struct B {
B();
B(B &&) { /* logging, etc., to verify if needed. */ }
private:
B(B const &);
B const &operator=(B const &);
};
B bar() {
B b;
// This is apparently allowed via the move constructor.
return b;
};
int main() {
// From this "side" of the call as well.
B b1 = bar();
B b2{bar()};
}
In what contexts are move constructors allowed or actually preferred by the language? Temporary return values seem fair to move (and trash contents of), but I'd like to find the core language rule for all places where the move can be silently used. Thanks!
asked 59 secs ago
Aucun commentaire:
Enregistrer un commentaire