![]() |
| | #1 |
| Registered User Join Date: Nov 2006 Location: japan
Posts: 107
| 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: 10,923
| 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: 107
| 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: 10,923
| 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: 369
| Quote:
Quote:
Code: class foo
{
private:
int milliseconds;
public:
void time(int);
};
void foo::time(int milliseconds)
{
this->milliseconds = milliseconds; // versus saying 'milliseconds = milliseconds'
}
__________________ home page (new layout) | ||
| scwizzo is offline | |
| | #6 |
| Registered User Join Date: Jan 2005
Posts: 7,221
| >> 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,187
| 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.
__________________ So let me get this straight. There is a food shortage in Haiti and you want me to donate money instead of food, because its cheaper to ship money to Haiti to buy food locally than to ship the food there. So where the ........ is the shortage if they have the food there already? As usual - "If money can fix the problem, then people are intentionally causing the problem". |
| abachler is offline | |
| | #8 | |
| Algorithm Dissector Join Date: Dec 2005 Location: New Zealand
Posts: 2,654
| 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 | |
| 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 |