Deletion of copy-ctor & copy-assignment - public, private or protected?

前端 未结 5 784
感情败类
感情败类 2020-12-15 02:54

In order to make an object non-copiable we can explicitly delete both its copy-constructor and copy-assignment operator.

My question is: What is the right place to

5条回答
  •  伪装坚强ぢ
    2020-12-15 03:35

    delete works just as well with private access.

    The effect of delete is to cause an error if the function is chosen by overload resolution.

    The effect of private is to cause an error if the function is chosen by overload resolution from outside the class or its friends.

    If both errors apply, the ultimate outcome is the same either way, but public might help avoid compiler messages about access privileges, which could cause confusion.

提交回复
热议问题