restructuring name hiding around the notion of hijacking
Max Samukha
spambox at d-coding.com
Fri Oct 2 06:25:42 PDT 2009
On Fri, 2 Oct 2009 08:54:49 -0400, Michel Fortin
<michel.fortin at michelf.com> wrote:
>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; }
Yes, I do it all the time. Thanks!
More information about the Digitalmars-d
mailing list