Delayed const variable initialization
ketmar via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Jul 13 01:55:00 PDT 2015
On Mon, 13 Jul 2015 07:11:32 +0000, Yuxuan Shui wrote:
> How can I do something like this?
>
> const(A) x;
> if (condition) {
> x = func1();
> } else {
> x = func2();
> }
>
> This is a valid use case, and to make this work I'll have to use
> Rebindable, which is really inconvenient.
p.s. also, this is not "initialization", but "assignment". `x` is
initialized to default value here, and then compiler will not allow
assignments. unlike c/c++, in D variables are always initialized.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20150713/d1210051/attachment.sig>
More information about the Digitalmars-d-learn
mailing list