Use of "this" keyword in C++ -
possible duplicate:
is excessive use of in c++ code smell
when should use "this" keyword in c++?
is there reason use this->
in c++, keyword "this" omitted? example:
person::person(int age) { _age = age; }
as opposed to:
person::person(int age) { this->_age = age; }
yes, not required , omitted. might required accessing variables after have been overridden in scope though:
person::person() { int age; this->age = 1; }
also, this:
person::person(int age) { _age = age; }
it pretty bad style; if need initializer same name use notation:
person::person(int age) : age(age) { }
Comments
Post a Comment