Macros to disallow class copy and assignment. Google -vs- Qt

前端 未结 11 1270
伪装坚强ぢ
伪装坚强ぢ 2020-12-13 06:22

To disallow copying or assigning a class it\'s common practice to make the copy constructor and assignment operator private. Both Google and Qt have macros to make this eas

11条回答
  •  轮回少年
    2020-12-13 06:54

    Others have already answered why it's legal to have different return values for operator=; IMHO jalf said it best.

    However, you might wonder why Google uses a different return type, and I suspect it's this:

    You don't have to repeat the type name when disabling the assignment operator like this. Usually the type name is the longest part of the declaration.

    Of course, this reason is void given that a macro is used but still - old habits die hard. :-)

提交回复
热议问题