Search code examples
c++naming-conventionsfunction-parameter

Accessing data members shadowed by parameters


In Java you can access variables in a class by using the keyword this, so you don't have to figure out a new name for the parameters in a function.

Java snippet:

private int x;

public int setX(int x) {
  this.x = x;
}

Is there something similar in C++? If not, what the best practice is for naming function parameters?


Solution

  • If you want to access members via this, it's a pointer, so use this->x.