[Issue 5850] Default arguments of out and ref arguments

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Dec 11 01:38:51 PST 2012


http://d.puremagic.com/issues/show_bug.cgi?id=5850


Andrej Mitrovic <andrej.mitrovich at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |andrej.mitrovich at gmail.com
         Resolution|                            |DUPLICATE


--- Comment #1 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2012-12-11 01:38:32 PST ---
This is related to Issue 7603.

Not that your sample won't compile anymore. What will compile is this:

int outerX = 1;
int outerY;

void foo(out int x = outerX, ref int y = outerY) { y = 2; }

void main()
{
    int innerX, innerY;

    foo(innerX, innerY);
    assert(innerX == 0 && innerY == 2);
    assert(outerX == 1 && outerY == 0);

    foo();
    assert(outerX == 0 && outerY == 2);
}

So 'out' and 'ref' default arguments refer to what variables are referenced,
not what values are written. Maybe you should open a documentation enhancement
request so the above is added to the docs to clear out any confusion for
newbies.

*** This issue has been marked as a duplicate of issue 7603 ***

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list