Saturday, May 22, 2010

I read modern C++ code and do not see "this->"?

I don't understand why I almost never see "this-%26gt;" used to reference variables internal to a class object. Is it depreciated, or is there a different way to imply this?

I read modern C++ code and do not see "this-%26gt;"?
C++ is rather old, so no its not depreciated. I cant think of many situations youd use that in, though.
Reply:It's just a convention, when accessing class member variables from within a class level function, their is an implicit "this-%26gt;" in front of variable access. Omitting it saves on typing, but adding it can improve code readability, allowing you to easily see what variables are class level scope.
Reply:You do not need it. Since "this-%26gt;x" is the same as "x". Unless x is defined in the local scope which would override the class scope.


No comments:

Post a Comment