C++ equivalent to Java this

空扰寡人 提交于 2019-11-30 06:03:45

Same word: this

Only difference is it is a pointer, so you need to use the -> operator:

void setX(int x)
{
    this->x = x;
}

The C++ equivalent is this, but there are a few differences.

This is a pointer to the object in question, not a reference; so, you must use pointer dereferencing operators before accessing fields or methods.

(*this).method(...)
(*this).field

or, using the more popular syntax

this->method(...)
this->field    

The C++ equivalent is this; that is, the keyword is the same.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!