Skip to content
Advertisement

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:

JavaScript

C++:

JavaScript

Advertisement

Answer

Same word: this

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

JavaScript
Advertisement