const ref type as return value

Namespace rswhite4 at googlemail.com
Fri Nov 29 01:55:56 PST 2013


On Friday, 29 November 2013 at 09:05:50 UTC, Oleg B wrote:
> [code]
> import std.stdio;
>
> struct A { int val; }
>
> A a;
>
> class X { const ref A func() { return a; } }
>
> void main()
> {
>     auto x = new X;
>     x.func().val = 5;
>     writeln( a );
> }
> [/code]
>
> in this case 'const' mean 'const method' and variable 'a' 
> changed.
>
> if write
> [code]
> class X { const(ref A) func() { return a; } }
> [/code]
ref const(A) func() { return a; }



More information about the Digitalmars-d-learn mailing list