Const vs Non const method

Namespace via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Feb 25 02:48:34 PST 2016


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);
	}
}
----



More information about the Digitalmars-d-learn mailing list