November 01, 2012 How do you copy a const struct to a mutable? | ||||
|---|---|---|---|---|
| ||||
I want to get this to compile:
void main()
{
struct A
{
this(int x) { this.x = x; }
int x;
}
const(A) a = A(5);
A b = a;
}
It should clearly be legal to create a non-const copy of the struct. What am I missing in order to do this?
Cheers,
Malte
| ||||
November 01, 2012 Re: How do you copy a const struct to a mutable? | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Malte Skarupke | Malte Skarupke:
> What am I missing in order to do this?
In D when you define a struct inside a function, it's not a POD any more.
If you define it as "static struct A" instead of "struct A", your code will compile.
Unfortunately DMD gives a too much generic error message in this case, it doesn't explain what's the problem:
test.d(7): Error: cannot implicitly convert expression (a) of type const(A) to A
Bye,
bearophile
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply