"The Cool Giraffe" <gi******@viltersten.comskrev i meddelandet
news:54*************@mid.individual.net...
John Harrison wrote/skrev/kaita/popisal/schreibt :
>>As for the this-dot or this-arrow wondering. I've
been tought to be explicit in order to avoid errors
believing to be in one scope but actually being
elsewhere. Perhaps it's just a bad habit. :)
I generally name class variables with a leading underscore. That way I
don't get confused between class variables and method parameters (or,
ugh, global variables).
class X
{
private:
int _count;
int _thing;
double _whatever;
public:
...
};
Thanks for that. Perhaps i'll use it too.
You will have to think about this one first. :-)
While technically allowed to use a single leading underscore in class member
names, those names are reserved in the global namespace for use by the
implementation. This means that _whatever could be either a local class
member, or a global name for compiler specific extension. Is that a good
convention?
However, i had
one more question. You wrote this.
"You can just say:
number = 5;
and it will use the number local to the class.
If you want to use the global number you would use:
number = 5;"
This works fine, if there is only one name. The first one visible will be
chosen.
>
Did you mean that? I was expecting
this->number or number in the first case
and ::number in the latter.
This way you specify which one you intended to use. Often it is obvious from
the context which one you should use. In that case, adding scope resolution
to everything would make me stop and wonder why you have chosen to do so. I
think that it would add more confusion than clarity.
If you don't name your classes X, it will be more obvious if they could hold
a 'number' or not.
Bo Persson