Why copy constructor and assignment operator are disallowed?

后端 未结 3 1246
面向向阳花
面向向阳花 2020-12-19 07:07
#undef GOOGLE_DISALLOW_EVIL_CONSTRUCTORS
#define GOOGLE_DISALLOW_EVIL_CONSTRUCTORS(TypeName)    \\
   TypeName(const TypeName&);                           \\
            


        
3条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-19 07:32

    To prevent instances of the class being copied or assigned. Most classes should not allow copying. Consider for example a BankAccount class - if you are writing software for a bank, they will not be too happy if you create copies of accounts and then apply credits and debits to those different copies.

提交回复
热议问题