Incorporating D
Adam D. Ruppe
destructionator at gmail.com
Fri Jan 25 14:29:43 PST 2013
On Friday, 25 January 2013 at 22:22:44 UTC, Szymon wrote:
> So structs in D are always passed by-value? That is
> unfortunate...
It has both pointers and ref but they both only work with
lvalues, regardless of const:
struct S {}
void test(const ref S s) {}
void test2(const S* s) {}
S getS() { return S(); }
void main() {
S s;
test(s); // ok
test2(&s); // ok
test(getS()); // not ok (line 12)
test2(&getS()); // not ok (line 13)
}
test.d(12): Error: function test.test (ref const(S) s) is not
callable using argument types (S)
test.d(12): Error: getS() is not an lvalue
test.d(13): Error: getS() is not an lvalue
More information about the Digitalmars-d
mailing list