Home  >  Q&A  >  body text

C++ 里面default的作用是什么?

我的意思是:既然我已经重载了拷贝控制函数/运算符,为什么还要保留编译器自动生成的合成拷贝控制呢?

ringa_leeringa_lee2765 days ago753

reply all(2)I'll reply

  • 迷茫

    迷茫2017-04-17 13:19:23

    Personally, I think that sometimes overloading copy constructors/operators is to show that copy control related functions have been taken into account when creating a class. When the copy control function synthesized by the compiler meets the needs, use =default You don’t have to write it yourself again. If other data members are added to the class in the future and copy control needs to be customized, there is no need to add copy constructors/operators, but only need to modify the existing ones.

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 13:19:23

    is equivalent to the last else in
    if...else if...else...
    . The meaning is the same

    reply
    0
  • Cancelreply