Is it bad to have the same name for parameter as for member variable?

c++, parameters, syntax, this

Solution

The only issue(not a real issue) I can think of is that you can't distinguish `member variable` with `local variable` or `function parameter`. It's just coding style, it's nothing to do with efficiency, but when you talk about `Unreadable`, that's yes for me.

For me I normally name class member variable with trailing underscore. It helps code readability and makes it easier for maintenance.

class Person {    
    public:
        string name_;                // member variable with traling `_`
        string m_surname;            // some microsoft style declares member start with `m_`
        Person(const string& name)   // pass parameter by reference. 
        : name_(name)                // you know you are constructing member name_ with name variable
        {
        }

};

Problem

For example, is this any of the following - Bad practice - Unreadable - Inefficient (the call to `this` pointer) - Any other reason why it's bad to do this . ``` class Person { public: string name; Person(string name) { this->name = name; } }; ``` P.S. How about `Person(string name) : name(name) { }`

Original source

Related problems