C++ copy constructor invocation

前端 未结 5 1658
轮回少年
轮回少年 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:44

    A copy constructor might not be invoked when you return by value. Some compilers use return value optimization feature.

    Read about "Return Value Optimization"

提交回复
热议问题