using "this"

Started by
11 comments, last by iMalc 18 years, 8 months ago
Quote:Original post by Perost
Well, you learn something new everyday. I am truly sorry for ever doubting you, oh great Fruny [smile]


I learned about it when I upgraded and saw the compiler barf on my code. I have no merit - I just found about it, the hard way (much frantic code twiddling and anguished googling), before you did. [wink]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Advertisement
*Adds two-stage name lookup to bag of obscure knowledge*
Quote:Original post by Fruny
Quote:Original post by iMalc
No, but you only ever need to use "this->" if you have local variables with the same names as members, which may be a bad idea anyway.


That's not the only case. If you have a class template and are referring to a base class template member, it is necessary to either specify this-> or properly qualify the name:

      foo = 42;          // Doesn't work      this->foo = 42;    // Works      Base<T>::foo = 42; // Works
Wow, I didn't know about that two-stage name lookup stuff, even though in the past I've had to use the Base<T>:: syntax, (which I prefer actually).
Technically my statement still stands, as it seems that using this-> is merely one of two ways of overcomming the situation. Not meaning to sounds too picky though. Thanks for the info!
"In order to understand recursion, you must first understand recursion."
My website dedicated to sorting algorithms

This topic is closed to new replies.

Advertisement