![]() |
| | #1 |
| Registered User Join Date: Nov 2006 Location: japan
Posts: 120
| I would like to know what is the difference between Code: this->method() Code: method() Thanks in advance
__________________ Mac OS 10.6 Snow Leopard : Darwin |
| nacho4d is offline | |
| | #2 |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 12,704
| 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 Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way |
| laserlight is online now | |
| | #3 |
| Registered User Join Date: Nov 2006 Location: japan
Posts: 120
| 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 |
| nacho4d is offline | |
| | #4 | |
| C++ Witch Join Date: Oct 2003 Location: Singapore
Posts: 12,704
| Quote:
__________________ C + C++ Compiler: MinGW port of GCC Build + Version Control System: SCons + Bazaar Look up a C/C++ Reference and learn How To Ask Questions The Smart Way | |
| laserlight is online now | |
| | #5 | ||
| Registered User Join Date: Mar 2007
Posts: 408
| Quote:
Quote:
Code: class foo
{
private:
int milliseconds;
public:
void time(int);
};
void foo::time(int milliseconds)
{
this->milliseconds = milliseconds; // versus saying 'milliseconds = milliseconds'
}
__________________ My Blog | ||
| scwizzo is offline | |
| | #6 |
| Registered User Join Date: Jan 2005
Posts: 7,280
| >> 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. |
| Daved is offline | |
| | #7 |
| Malum in se Join Date: Apr 2007
Posts: 3,188
| 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. |
| abachler is offline | |
| | #8 | |
| Algorithm Dissector Join Date: Dec 2005 Location: New Zealand
Posts: 3,195
| Quote:
Code: foo(a, b, c); Code: foo(this->a, this->b, this->c); You wont catch me putting tons of redundant clutter in there!
__________________ 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" | |
| iMalc is offline | |
![]() |
| Tags |
| this usage? |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| on method pointers and inheritance | BrownB | C++ Programming | 2 | 03-02-2009 07:50 PM |
| stuck on display method | shintaro | C++ Programming | 2 | 02-01-2009 05:17 PM |
| Best communication method to thousand childs? | Ironic | C Programming | 8 | 11-08-2008 12:30 AM |
| C# method | siten0308 | C# Programming | 6 | 07-15-2008 07:01 AM |
| Overriding a method in C | DavidDobson | C Programming | 1 | 07-05-2008 07:51 AM |