restructuring name hiding around the notion of hijacking

Michel Fortin michel.fortin at michelf.com
Fri Oct 2 05:54:49 PDT 2009


On 2009-10-02 08:29:09 -0400, Max Samukha <spambox at d-coding.com> said:

> class Counted {
>      mixin(Derived)
>      {
>          // Insert here stuff that must be "pasted" for each subclass
>          // of Counted (including Counted itself).
>          // Use "Derived" as the name of the current subtype of
> Counter
>          private static uint _counter;
>          uint staticCounter() { return _counter; }
> 
>          static if (is(Counted == Derived))
>              uint getCounter() { return staticCounter; }
>          else
>              override uint getCounter() { return staticCounter; }
>      }
>      ...
> }
> 
> The counter variable is now incapsulated.

Hum, I think you forgot to make staticCounter static, as in:

	static uint staticCounter() { return _counter; }

-- 
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/




More information about the Digitalmars-d mailing list