jeudi 24 décembre 2015

in what case the move constructor is used except std::move? [duplicate]

This question already has an answer here:

One page 115 of "The C++ Programming Language Fourth Edition" by "Bjarne Stroustrup", which talk about move and copy operators and constructors, it says:

Vector f()

{
    Vector x(1000);
    Vector y(1000);
    Vector z(1000);
    // ...
    z = x;             // we get a copy
    y = std::move(x);  // we get a move
    // ...
    return z;          // we get a move

What interesting me is the last line that says return a value will call move constructor.

But in my code, I define a class ssyvector with both move constructor and operator. I find that neither the move constructor or move operator are called in the following program:

ssyvector ret_ssyv() {
  ssyvector sv(21);
  return sv;
}
...
ssyvector sdf(ret_ssyv());
ssyvector sdf1 =ret_ssyv();

Can anyone explain this?

Aucun commentaire:

Enregistrer un commentaire