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![]()
This is a discussion on difference between this->method() and method() within the C++ Programming forums, part of the General Programming Boards category; Hi, I would like to know what is the difference between Code: this->method() and the simple Code: method() I found ...
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?
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way
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
C + C++ Compiler: MinGW port of GCC
Version Control System: Bazaar
Look up a C++ Reference and learn How To Ask Questions The Smart Way
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.
Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off.
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"