Implicit const
Ary Borenszweig
ary at esperanto.org.ar
Thu Apr 3 04:01:03 PDT 2008
Janice Caron escribió:
> On 03/04/2008, Bill Baxter <dnewsgroup at billbaxter.com> wrote:
>> However, when the compiler compiles getA, it can actually tell pretty
>> easily, that, yeh, getA is really also OK as const. So at least for such
>> simple cases, it seems that the explicit labeling is not really necessary.
>
> I've thought about this before, and it seems to me that, if D had
> warnings, it would be a good call to issue a warning for any function
> which /could/ have declared itself const, but didn't. Ditto any
> function parameter.
>
> Similarly,
>
> class C
> {
> int f()
> {
> return 42;
> }
> }
>
> the compiler is in a position to say "Wait a minute - you could have
> declared f static, but didn't".
But maybe you want that function to be overriden by subclasses. Maybe if
it were "final int f()", then it could say that.
What about const? Does a const function must be overriden by a const
function?
More information about the Digitalmars-d
mailing list