Consider following code snippet:
struct S
{
S( const int a )
{
this->a = a; // option 1
S::a = a; // option 2
}
int a;
};
Is option 1 is equivalent to option 2? Are there cases when one form is better than another? Which clause of standard describes these options?
Have you tried this option?
Have a look at the following:
Both forms are identical unless
a
is a virtual function. I'd preferthis->a
, because it does what I usually want even ifa
is a virtual function. (But isn't it better to avoid the name clash to begin with.)option 1 is equivalent to option 2, but option 1 will not work for a static data member
EDITED: static data members can be accessed with this pointer. But this->member will not work in static function. but option 2 will work in static function with static member
Eg: