When Does Move Constructor get called?

前端 未结 3 1134
小蘑菇
小蘑菇 2020-12-02 09:24

I\'m confused about when a move constructor gets called vs a copy constructor. I\'ve read the following sources:

Move constructor is not getting called in C++0x

3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-02 09:57

    Remember that copy elision could occur. If you disable it by passing the -fno-elide-constructors flag to the compiler your constructor might get executed.

    You can read about it here: https://www.geeksforgeeks.org/copy-elision-in-c/

提交回复
热议问题