Home  >  Q&A  >  body text

c++ - 移动语义中的std::move()

   #include <iostream>   
                        
   using namespace std;  
                         
   int main()            
   {                     
       int a = 2;        
       cout << &a << endl;
       std::move(a);     
       cout << &a << endl;
       a = 3;
       cout << a << endl;                                                                                
       return 0;         
  } 

std::move()不是可以把一个左值转换成右值吗?为什么a在使用了move函数后,还可以被赋值?为什么a在使用了move函数后,还可以获取地址?一个右值不是不可以寻址吗?

PHP中文网PHP中文网2713 days ago498

reply all(1)I'll reply

  • PHP中文网

    PHP中文网2017-04-17 13:51:19

    std::move is returning an rvalue reference.

    The implementation of std::move is a static_cast.

    reply
    0
  • Cancelreply