C++ copy constructor invocation

前端 未结 5 1660
轮回少年
轮回少年 2021-01-11 15:02

As far as i know, a copy constructor is invoked in the following scenarios :

1) Pass by value
2) Return by value
3) When you create and initialize a new obje         


        
5条回答
  •  逝去的感伤
    2021-01-11 15:35

    In your exampe the structure is small enough therefore it is passed through a register. The generated code is similar to Return value optimization. Construct a more complicated example, and you'll see the behavior expected.

提交回复
热议问题