'final' variables

Andrei Alexandrescu (See Website For Email) SeeWebsiteForEmail at erdani.org
Tue Mar 20 09:25:10 PDT 2007


Sean Kelly wrote:
> Stewart Gordon wrote:
>> Tyler Knott Wrote:
>>> Lionello Lunesu Wrote:
>>>> What's the use of "final" for variables?  I'm saying "for variables" 
>>>> because for methods the benefit is only too clear.
>>> Because the "const" keyword is being repurposed for read-only 
>>> references to mutable or non-mutable data, we need a new keyword for 
>>> non-mutable variables.
>> <snip>
>>
>> C++ manages with const for both, so why can't D?
>  > What circumstance is there in which either keyword would be valid
>  > with different meanings?
> 
> Some D reference types do not have the pointer qualifier, so this C++ 
> declaration:
> 
>     int const * const x;
> 
> could not be directly reproduced in D, except for maybe:
> 
>     int const [] const x;
> 
> which is horrifying :-)  And it still doesn't address the issue of class 
> references.

I _swear_ I hadn't seen this post when posted one with the same syntax 
in it :o).

Andrei



More information about the Digitalmars-d mailing list