Hi,
I would like to know what is the difference between
and the simpleCode:this->method()
I found that both compile and seems to be ok, but I suppose there should be a difference.Code:method()
Thanks in advance
Hi,
I would like to know what is the difference between
and the simpleCode:this->method()
I found that both compile and seems to be ok, but I suppose there should be a difference.Code:method()
Thanks in advance
Mac OS 10.6 Snow Leopard : Darwin
Assuming that member is a member function and the call is from within a member function of the class, they are usually equivalent, but the former can be useful if disambiguation of names is needed, or in another related case: Why am I getting errors when my template-derived-class uses a member it inherits from its template-base-class?
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Thanks LaserLight,
So a good idea would be to use "this->method()" everytime if possible? (when calling members)
Mac OS 10.6 Snow Leopard : Darwin
In my opinion, no, since it is usually just clutter.Originally Posted by nacho4d
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
I believe what laser light means by this is something similar to the following.
Code:class foo { private: int milliseconds; public: void time(int); }; void foo::time(int milliseconds) { this->milliseconds = milliseconds; // versus saying 'milliseconds = milliseconds' }
>> In my opinion, no, since it is usually just clutter.
I agree. In fact, if you don't use this-> unless it is necessary, it helps make it clearer that it is necessary if you ever do use it.
I use it every time, but hen I prefer my code to be clear and concise and easily maintainable. If you leave this-> out, you may regret it some day when you make changes that make it necessary and you have to track through 1000 lines of code to find the problem.
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"