Maison  >  Questions et réponses  >  le corps du texte

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 Il y a quelques jours500

répondre à tous(1)je répondrai

  • PHP中文网

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

    std::move是返回一个rvalue reference。

    std::move的实现就是一个static_cast。

    répondre
    0
  • Annulerrépondre