On 03/23/2012 11:28 PM, Dan wrote:
> When would you use in / out parameters instead of ref & const keywords?

I am just about finished translating a chapter exactly on that topic. I've just realized that I have some questions myself. :)

'out' is the equivalent of a reference in C++, with additionally initializing the out parameter upon entry to the function.

void foo(out int i)
{
    assert(i == 0);  // regardless of what it was before the call
}

'in' is the same as 'const scope'. const part is easy to understand but I don't know what 'scope' does. I could not understand what the spec means with "references in the parameter cannot be escaped (e.g. assigned to a global variable)" for scope:

  http://dlang.org/function.html

'ref' is the same as a C++ reference.

Ali

Reply via email to