Static struct assign

bearophile bearophileHUGS at lycos.com
Thu Mar 11 09:22:21 PST 2010


While trying to create a safe int, I have found a problem, this is reduced code:

struct Foo {
    int x;
    static Foo opAssign(int value) { return Foo(value); }
}
void main() {
    Foo y = 0;
}


The compiler prints:
test.d(6): Error: cannot implicitly convert expression (0) of type int to Foo

While this generates no error:
Foo y; y = 0; is OK.

Do you know if there is a way to do that?

Bye and thank you,
bearophile


More information about the Digitalmars-d-learn mailing list