Const vs Non const method

Andrea Fontana via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Feb 25 02:53:09 PST 2016


On Thursday, 25 February 2016 at 10:48:34 UTC, Namespace wrote:
> Try inout:
> ----
> import std.stdio;
>
> struct Inner
> {
> 	int field = 3;
> }
>
> struct Test
> {
> 	
> 	auto get() inout { return inner; }
> 	
> 	private Inner inner;
> }
>
>
> void main()
> {
> 	
> 	{
> 		Test test;
> 		test.get.field = 4;
> 	}
> 	
> 	{
> 		immutable Test test;
> 		writeln(test.get.field);
> 	}
> }
> ----

Uh, I didn't know inout can be used with function. I think it was 
used only with params/return. Thank you :)




More information about the Digitalmars-d-learn mailing list