In which situations is the C++ copy constructor called?

后端 未结 7 1698
梦毁少年i
梦毁少年i 2020-12-23 02:06

I know of the following situations in c++ where the copy constructor would be invoked:

  1. when an existing object is assigned an object of it own class

7条回答
  •  醉酒成梦
    2020-12-23 03:03

    The following are the cases when copy constructor is called.

    1. When instantiating one object and initializing it with values from another object.
    2. When passing an object by value.
    3. When an object is returned from a function by value.

提交回复
热议问题