When should I use “this” in a class?

后端 未结 18 2143
情书的邮戳
情书的邮戳 2020-11-21 23:36

I know that this refers to a current object. But I do not know when I really need to use it. For example, will be there any difference if I use x i

18条回答
  •  囚心锁ツ
    2020-11-21 23:59

    To make sure that the current object's members are used. Cases where thread safety is a concern, some applications may change the wrong objects member values, for that reason this should be applied to the member so that the correct object member value is used.

    If your object is not concerned with thread safety then there is no reason to specify which object member's value is used.

提交回复
热议问题