Group: comp.lang.c++
From: "Jim Langston"
Date: Tuesday, April 08, 2008 5:01 PM
Subject: Re: Stigma attached to "this"

gw7rib@aol.com wrote:
> I was modifying a program recently, and felt that I hadn't really got
> the responsibilities of the various classes quite right. Consequently
> I was having to use "this" a lot. It got me thinking - do people use
> the presence of "this" to suggest that there might be problems? Do
> they view it, like "goto", as something for which there are legitimate
> uses but which in general indicates that a piece of code has not been
> fully thought through? Or does it have no such stigma?
>
> All thoughts welcome!
> Paul.

In my own code I almost never use this. Mainly because I don't have
parameters the same name as class variables.

There are a few schemes people use to make sure that class variables are not
the same as parameters, the one I use is suceeding all class variables with
an underscore. I.E.

class Foo
{
public:
void DoSomething( int Bar ) { Bar_ = Bar; }
private:
int Bar_;
};

If the class variable was the same as the parameter then I'd have to use
this:
void DoSomething( int Bar ) { this->Bar = Bar; }


--
Jim Langston
tazmaster@rocketmail.com


Safety Articles | Usenet Groups | Usenet News | Bluegrass