In C++, you can, if you want:
struct A {
int x;
A(int x) : x(x) {
foo(this->x);
// if you want the member instead of the parameter here
}
};
Though I also commonly use stylistic names for members (e.g. _x
), I do it for non-public members. If x
is public as in this example, I would do it like this, and look at renaming the ctor's parameter if I thought it would be more readable.
Edit: Since people seem to be getting sidetracked, I'll clarify on _x
. The standard reserves some identifier names:
- any name with two adjacent underscores, in any namespace
- any name with a leading underscore followed by an uppercase letter, in any namespace
- any name with a leading underscore at global scope
Since members are scoped to the class, they do not fall in the third category. That said, it would be nice to not continue getting sidetracked. :) Feel free to ask a question about reserved identifiers in C++ and post a link to it in the comments if you want.