roxen.lists.pike.general

Subject Author Date
Re: "this" keyword in constructors (7.8) Henrik_Grubbström <grubba[at]roxen[dot]com> 10-03-2009
On Tue, 10 Mar 2009, Jeff Ober wrote:

> Private members are not available using "this" from create().  For example:
>
> private int foo;
>
> void create(int foo)
> {
>  this->foo = foo;
> }
>
> Is this the expected behavior?

As others have already answered: Yes, this is the intended behaviour, the 
->-operator indexes an object from "outside", and is thus affected by both 
of private and protected.

Forcing resolution in the current object (rather than in the set of local 
variables) without resorting to renaming of symbols can be done with the 
::-operator:

   o this_program::x
       The symbol x in the current class.
   o local::x
       The symbol x in the current class accessed as if the symbol was
       declared local (ie bypassing overloading).
   o ::x
       The inherited symbol x in the current class.
   o global::x
       The symbol x in the (implicit) outermost class of the compilation
       unit.
   o A::x
       The inherited symbol x from the inherit A in the current class.
       Or the symbol x in the lexically nested (including the current)
       class with the name A.
   o A::B::x
       Same lookup for A as above, but then the symbol x in the inherit B
       in A.
   o global::B::x
       The symbol x from the inherit B in the outermost class.

For completeness I'll list the following two syntaxes as well:

   o predef::x
       The symbol x from the set of all_constants().
   o 7.4::x
       The 7.4 compatibility implementation of the symbol x (this syntax
       was added in Pike 7.8).

> It's not a big problem and can be avoided by renaming create's
> parameters, but it is inconvenient since there are only so many
> descriptive variable names :).
>
> Jeff Ober
> -- 
> Old programmers don't die; they just parse on...

--
Henrik Grubbström					<grubba[at]roxen.com>
Roxen Internet Software AB