move Constructor is not called

萝らか妹 提交于 2019-12-06 04:13:22

That you don't see move construction or move assignment is simply a result of optimization! Please take a look for "copy elision" https://en.cppreference.com/w/cpp/language/copy_elision

If you are using gcc you can tell the compiler to don't optimize it by:

g++ -O0 main.cpp -fno-elide-constructors

Now the result is:

Constructor called with size: 5
Move Constructor called
Destructor called
Destructor called
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!