If you're using initialization list syntax, the names of the arguments can be the same as the member names, and the compiler is smart enough to know what to do:
Code:
Point(int x, int y) : x(x), y(y) {}
Code:
Point(int x,int y)
{
Point::x=x;
Point::y=y;
}
};
This would work if x and y were static, for non-static members, you could alternatively do this:
Code:
Point(int x,int y)
{
this->x=x;
this->y=y;
}
};
The initialization list is the preferred way to do this in a constructor, but you can use this in any other place you need to differentiate a member variable from a local, for example.