static vs non-static

Maxim Fomin maxim at maxim-fomin.ru
Tue Jan 15 23:05:27 PST 2013


On Tuesday, 15 January 2013 at 22:03:24 UTC, Era Scarecrow wrote:
> On Sunday, 13 January 2013 at 16:39:22 UTC, bearophile wrote:
>> Maxim Fomin:
>>
>>> dmd allows to call static functions on instance.
>>
>> I think that's a D design mistake (and I think Jonathan Davis 
>> agrees with me), but Walter prefers the current behavour.
>
>  I'll have to disagree and it should remain an error.
>
>  Consider his example, if it were allowed and you do:
>
>  Gun gun;
>  Gun.bar();
>  gun.bar();
>

The problem is that code depends on presence of static and 
no-static functions. If no one is preferred, compiler would issue 
error (like dmd behaves today), if one of them is preferred (for 
e.x. non-static) the semantic would be silently changed if you 
write gun.bar() and then add non-static function to class.


More information about the Digitalmars-d-learn mailing list