Consider the following class:
class A
{
A();
int number;
void setNumber(int number);
};
You could implement 'setNumber' in 3 ways:
Method 1: Use the 'this' pointer.
void A::setNumber(int number)
{
this->number = number;
}
Method 2: Use the scope resolution operator.
void A::setNumber(int number)
{
A::number = number;
}
Method 3: Instead, denote all member variables with 'm' or '_' (this is my preferred method).
void A::setNumber(int number)
{
mNumber = number;
}
Is this just personal preference, or is there a benefit to choosing a particular method?
I am going to agree with Luchian by providing a better variant. The other examples you provide are too cumbersome or confusing.
Option 4:
This is part of the coding standard we use at my employer and it is very clear what you are describing. It is not Hungarian notation.
It is a matter of style, thus personal preference, or a preference of the team you are working with or the boss of the team you are working with.
I would say the choice between Method 1 and Method 3 is a matter of personal or organizational style.
Method 2 is an inferior because Class::member typically denotes a static member variable, and thus would cause confusion if used to disambiguate between a parameter and member variable.
Option 4:
Why is the benefit of using the same name for a member and a parameter. No good can come of this. Sure, it's clear now, but when your methods get large, and the prototype doesn't fit in the screen anymore, and there's some other developer writing code, he may forget to qualify the member.
its all personal preference
but here is a good discussion on it at a high non language level
https://stackoverflow.com/questions/381098/what-naming-convention-do-you-use-for-member-variables
This is mostly a personal preference, but let me share my perspective on the issue from inside a company where many small games are being made simultaneously (and so there are many coding styles being used around me).
This link has several good, related, answers: Why use prefixes on member variables in C++ classes
Your option 1:
Your option 2:
Your option 3: