Passing structs to functions

Namespace via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jul 2 14:31:40 PDT 2016


Just for you, a slightly adapted version:

----
import std.stdio;

struct A {
	public int id = 0;
	
	this(int id) {
		this.id = id;
	}
	
	ref A byRef() {
		return this;
	}
}

void foo(ref const A a) {
	writeln(a.id);
}

void main() {
	foo(A(42).byRef());
}
----


More information about the Digitalmars-d-learn mailing list