using "this"
this may seem like a strange question.. but
in msvc++ does using "this" inside you class to refer to the class' data have any side effects, like extra lookup / slower performance.. ...just wondering..
example..
CBall::CBall()
{
m_size = 5;
}
CBall::CBall()
{
this->m_size = 5;
}
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. Using just "this" or "*this" is fine however.
I just used "this" for the intellisense autocomplete....and occasionally a stray "delete this;"
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:
template<class T> class Base{public: int foo;};template<class T> class Derived : public Base<T>{public: void do_stuff() { foo = 42; // Doesn't work this->foo = 42; // Works Base<T>::foo = 42; // Works }};int main(){ Derived<int> bar; bar.do_stuff();}
Fruny, are you sure that is the case? I tried your code, and it compiled without a warning on g++ 3.3.4 under linux.
I second Perost, are you sure about that Fruny?
I can do that in my GUI classes (derived from a templated class) and i do not ever need to use this-> to access those members (besides i think it looks fugly).
I can do that in my GUI classes (derived from a templated class) and i do not ever need to use this-> to access those members (besides i think it looks fugly).
Quote:Original post by Perost
Fruny, are you sure that is the case? I tried your code, and it compiled without a warning on g++ 3.3.4 under linux.
Upgrade to 3.4 and see it explode. The free lunch is over. [smile]
Well, you learn something new everyday. I am truly sorry for ever doubting you, oh great Fruny [smile]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement