I am trying to understand move semantics, so I did the following test:
#include <iostream>
#include <array>
using namespace std;
void tryToMove(array<double,3> && v) {
array<double,3> v_ = std::move(v);
std::cout << v_[0] << " " << v_[1] << " " << v_[2] <<'\n';
}
int main () {
array<double,3> v{1,2,3};
tryToMove(std::move(v));
std::cout << v[0] << " " << v[1] << " " << v[2] <<'\n';
}
I was expecting a sementation fault in the std::cout of the main since v_ is supposed to be moved in tryToMove. However, the output is:
1 2 3
1 2 3
What is exactly happening here?
Thank you!
Aucun commentaire:
Enregistrer un commentaire