Why C++ copy constructor must use const object?

后端 未结 8 1685
夕颜
夕颜 2020-11-30 02:18

I understand that when we define a class copy constructor of the class is necessary as Rule of three states. I also notice that the argument of the copy constructor is usual

8条回答
  •  粉色の甜心
    2020-11-30 02:44

    If the copy constructor doesn't specify it's parameter as const then this fragment would not compile.

    const ABC foo;
    ABC bar(foo);
    

提交回复
热议问题