const, final, scope function parameters

Denton Cockburn diboss at hotmail.com
Tue May 29 00:53:55 PDT 2007


On Mon, 28 May 2007 18:56:00 -0400, Robert Fraser wrote:

> Ah, thanks, now I understand scope (I understood the other two; I thought scope would prevent copies of references). Still, const by default seems a bit odd - make it explicit. For example, if a file stream is being passed to a function, could I write to it inside the function if it was const?
> 

No, not if it changes the internals of the object.
If you want that, then simply specify the parameter as 'ref'

void foo(ref Stream x) { ...blah... }
or
void foo(scope final Stream x) { ...blah... }

I'm trying to understand this too, so hopefully I didn't just tell you the
wrong thing.



More information about the Digitalmars-d mailing list