Skip to content

Tag: this

C++ equivalent to Java this

In Java you can refer to the current object by doing: this.x = x. How do you do this in C++? Assume that each of these code examples are part of a class called Shape. Java: C++: Answer Same word: this Only difference is it is a pointer, so you need to use the -> operator: