Copy constructor or = operator?

前端 未结 3 976
一整个雨季
一整个雨季 2021-01-18 04:40
    class Foo
    {


    };

    Foo f;
    Foo g = f; // (*)

My question is, what is being called in the line marked with (*) ? Is it the default

3条回答
  •  耶瑟儿~
    2021-01-18 05:06

     Foo g = f; // (*)
    

    copy constructor gets invoked .Its called copy initialization of object.

    If you have not written copy constructor within class Foo then compiler generated copy constructor gets called.

提交回复
热议问题